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 > insert row in a dynamically generated table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-09, 10:36
rocker86 rocker86 is offline
Registered User
 
Join Date: Jul 2009
Posts: 37
insert row in a dynamically generated table

hi, Is it possible in a stored procedure, to insert rows in a table that has just been created a few lines above?? I am writing a stored procedure on DB2 and it understandably gives an error on deployment that the "table u r trying to insert values into dsnt exist"

EXECUTE IMMEDIATE 'Create table xyz(...... )'

INSERT INTO xyz VALUES(... . .);

I wud be grateful for any help,

Regards
Reply With Quote
  #2 (permalink)  
Old 07-13-09, 12:44
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
Quote:
Originally Posted by rocker86
hi, Is it possible in a stored procedure, to insert rows in a table that has just been created a few lines above?? I am writing a stored procedure on DB2 and it understandably gives an error on deployment that the "table u r trying to insert values into dsnt exist"

EXECUTE IMMEDIATE 'Create table xyz(...... )'

INSERT INTO xyz VALUES(... . .);

I wud be grateful for any help,

Regards
You will need to put a 'commit' between 'CREATE TABLE' and 'INSERT'
Reply With Quote
  #3 (permalink)  
Old 07-13-09, 12:51
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by rocker86
hi, Is it possible in a stored procedure, to insert rows in a table that has just been created a few lines above?? I am writing a stored procedure on DB2 and it understandably gives an error on deployment that the "table u r trying to insert values into dsnt exist"

EXECUTE IMMEDIATE 'Create table xyz(...... )'

INSERT INTO xyz VALUES(... . .);

I wud be grateful for any help,

Regards
You need to make the insert dynamic also:

EXECUTE IMMEDIATE 'Create table xyz(...... )'

execute immediate 'INSERT INTO xyz VALUES(... . .)'

Andy
Reply With Quote
  #4 (permalink)  
Old 07-14-09, 07:03
rocker86 rocker86 is offline
Registered User
 
Join Date: Jul 2009
Posts: 37
Thanks a ton that worked..!!
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