🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.listserv.sqlinfo
Article #254

EXECUTE IMMEDIATE Terminates CURSOR

#254
From: 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;
Technical Details
Message-ID: <3CF4E22E.9467EB42@yahoo.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!zeus.visi.com!news-out.visi.com!ruti.visi.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11355a,78323ed4a1b90ac5,start
X-Google-Attributes: gid11355a,public
X-Google-ArrivalTime: 2002-05-29 07:15:08 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!zeus.visi.com!news-out.visi.com!ruti.visi.com!not-for-mail
Message-ID: <3CF4E22E.9467EB42@yahoo.com>
From: Pythagoras <Pythagoras@yahoo.com>
X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: bit.listserv.sqlinfo
Subject: EXECUTE IMMEDIATE Terminates CURSOR
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 38
Date: Wed, 29 May 2002 09:14:06 -0500
NNTP-Posting-Host: 208.42.117.141
X-Complaints-To: abuse@visi.com
X-Trace: ruti.visi.com 1022681707 208.42.117.141 (Wed, 29 May 2002 09:15:07 CDT)
NNTP-Posting-Date: Wed, 29 May 2002 09:15:07 CDT