If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > stored proc with table alteration function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-07-04, 05:52
mylee mylee is offline
Registered User
 
Join Date: Jun 2004
Posts: 1
stored proc with table alteration function

I would like to ask is there any possibility for us to write a stored proc with table alteration statement? I have came across several stored procs but found that most of them are for select or joining tables purposes. Below is the stored proc sql statement:

CREATE PROCEDURE IPMS.TESTID
(IN V_TABLE VARCHAR(20))

SPECIFIC IPMS.SQL040603171458060
LANGUAGE SQL
NOT DETERMINISTIC
CALLED ON NULL INPUT
MODIFIES SQL DATA
INHERIT SPECIAL REGISTERS

BEGIN
DECLARE v_Table1 VARCHAR(20);
DECLARE V_Max integer;

SET v_Table1 = V_Table;

DECLARE id_cursor CURSOR FOR
SELECT MAX(id) FROM test;
BEGIN

OPEN id_cursor;
FETCH FROM id_cursor INTO V_Max;

ALTER TABLE IPMS.v_Table1
LOCKSIZE ROW
APPEND OFF
NOT VOLATILE
ALTER COLUMN ID
RESTART WITH V_Max;

CLOSE id_cursor;
END;

END;


I tried to run the above stored proc and get this error:
[IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "ALTER TABLE IPMS.v_Table1 L" was found following "d_cursor INTO V_Max;". Expected tokens may include: "<psm_labellable_stmt>". LINE NUMBER=1. SQLSTATE=42601

I'm new in compiling stored proc. Can anyone give me some guide on this?

Thanks in advance.

Regards.
Reply With Quote
  #2 (permalink)  
Old 06-23-04, 13:28
dmmac dmmac is offline
Registered User
 
Join Date: Aug 2003
Location: Massachusetts, USA
Posts: 106
Refer to documentation on 'PREPARE' and 'EXECUTE'. This will allow you to dynamically prepare a SQL statement then execute the variable that holds that SQL statement.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On