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 > DB2 Temporary Tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-16-07, 04:12
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
DB2 Temporary Tables

i have a stored procedure A in which i create a temporary tables...say X
and has the following logic
procedure A

create temp table X;
insert into X (select from sometable where some criteria);

while (select count(*) from X ) > 0
do

some processing

delete one row from X

end while


i need the table to store some values and then run a while loop deleting a row each time.....

now hundreds of users will be accessing mt procedure at the same time so i cant use a global temp table......then how to go about it.....i need something on the lines of a local temporary table......

Last edited by nick.ncs; 07-16-07 at 04:20.
Reply With Quote
  #2 (permalink)  
Old 07-16-07, 08:26
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Global temporary tables are not visible to all users. Just the user that DECLARE them.

Andy
Reply With Quote
  #3 (permalink)  
Old 07-16-07, 13:04
nick.ncs nick.ncs is offline
Registered User
 
Join Date: May 2007
Location: somewhere in dbforums
Posts: 221
ok....got that after lot of peeking around......but it seems suppose a user fires procedure A then the temporary table will be created but the same user could not fire the same procedure in the same seesion........

basically what i found was have to open a seperated instance of command editor each time to fire the same procedure, the same instance would always give the error that the temporary table already exists....
Reply With Quote
  #4 (permalink)  
Old 07-16-07, 13:21
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
If you add the clause "WITH REPLACE" on the "DECLARE GLOBAL TEMPORARY TABLE", DB2 will replace the old definition with the new. Alternately, you can issue a "DROP TABLE session.MyGlobalTemporaryTable" type command when you are finished with the table.

Andy
Reply With Quote
  #5 (permalink)  
Old 07-16-07, 14:24
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Or you add a condition handler that intercepts and ignores the error that DB2 raises on the second DECLARE statement...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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