🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: bit.listserv.sqlinfo
1 messages
1 total messages Started by Pythagoras Wed, 29 May 2002 14:14
EXECUTE IMMEDIATE Terminates CURSOR
#254
Author: Pythagoras
Date: Wed, 29 May 2002 14:14
37 lines
2138 bytes
The following batch works for the first table that is returned via the
TblPtr cursor. (Using the MESSAGE 'TblName = ', TblName TO CLIENT;
statement without the EXECUTE IMMEDIATE statement shows that the cursor
returns all tables of concern.) The error is ASA Error-180: Cursor not
open. Any suggestions as to why this does not work or alternative
methods of adding a column to all tables in a given database using a
script would be greatly appreciated.

BEGIN
  DECLARE TblPtr CURSOR FOR
    SELECT Table_Name
        FROM SYS.SYSTABLE
       WHERE Creator=1 AND
             Table_Type='BASE'
       ORDER BY Table_Name;
  DECLARE TblName LONG VARCHAR;
  CREATE VARIABLE TblNum INTEGER;
  CREATE VARIABLE NumTbls INTEGER;
  SET TblName='';
  SET TblNum=0;
  SELECT COUNT(*)
    INTO NumTbls
    FROM SYS.SYSTABLE
    WHERE Creator=1 AND
          Table_Type='BASE';
  OPEN TblPtr;
  TableLoop:
  WHILE TblNum<NumTbls LOOP
    SET TblNum=TblNum+1;
    FETCH NEXT TblPtr INTO TblName;
    EXECUTE IMMEDIATE 'ALTER TABLE ' || TblName || ' ADD NewCol000
TIMESTAMP;';
  END LOOP TableLoop;
  CLOSE TblPtr;
  DROP VARIABLE TblNum;
  DROP VARIABLE NumTbls;
END;
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads