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 > Declare global temporary table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-11, 08:55
10Pints 10Pints is offline
Registered User
 
Join Date: Nov 2010
Posts: 17
Smile Declare global temporary table

This declares a table that persists for the session.
I have need of a table for just the duration of an SP call really - but no matter this would do.

Question:
Can I use this declare statement in a procedure that is called more than once per session or do I need a special procedure that is only called once at start-up in which to declare the temporary table?


Many thanks

10Pints
Reply With Quote
  #2 (permalink)  
Old 12-08-11, 09:12
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You can declare it in the stored procedure that is called more than once, just use the "WITH REPLACE" clause.

Andy
Reply With Quote
  #3 (permalink)  
Old 12-08-11, 09:47
10Pints 10Pints is offline
Registered User
 
Join Date: Nov 2010
Posts: 17
Ah so - many thanks Andy!
Much appreciated.
10Pints
Reply With Quote
  #4 (permalink)  
Old 12-08-11, 15:07
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Another question is what you want to do with the table. Often I have seen something like this:
Code:
DECLARE GLOBAL TEMP TABLE t ...;
LOOP ...
    INSERT INTO t VALUES (...);
END LOOP;
DECLARE c CURSOR WITH RETURN FOR SELECT * FROM t;
In such a situation, you can often get along by avoid the temp table completely:
Code:
DECLARE c CURSOR WITH RETURN FOR SELECT * FROM TABLE ( VALUES (...), (...), ... ) AS t
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 12-20-11, 14:47
10Pints 10Pints is offline
Registered User
 
Join Date: Nov 2010
Posts: 17
Sorry for tardy reply - been away.
Yes that would be useful in many situations: I will bank that one

Many thanks

10Pints
Reply With Quote
Reply

Tags
temporary table

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