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 > Return cursor on temp table in stored procedure?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-10, 12:27
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Return cursor on temp table in stored procedure?

Hi,

I have two stored procedures, one that initializes a temp table and another that calls it..

SPROC1 : TEMP TABLE SPROC has something like this --

SET tmpStatement = 'DECLARE GLOBAL TEMPORARY TABLE SESSION.tmp_readings LIKE TMPREADINGS NOT LOGGED';

EXECUTE IMMEDIATE tmpStatement;
END



SPROC 2 : SPROC THAT USES TEMP TABLE --

CALL SPROC1() --- to define the temp table

DECLARE C1 CURSOR WITH RETURN FOR SELECT * from SESSION.tmp_readings;


The problem is this -- when I create SPROC2, it complains in the cursor statement above that SESSION.tmp_readings hasn't been defined yet. Is there some keyword I can give the DECLARE GLOBAL TEMPORARY TABLE statement so that it recognizes the table when it comes to the cursor statement? Thanks!!
Reply With Quote
  #2 (permalink)  
Old 08-18-10, 14:07
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
If you use dynamic SQL to declare the table, you should use the same to select from it, because you can refer to the table definition only at run time.
Reply With Quote
  #3 (permalink)  
Old 08-19-10, 09:46
wilsonfv wilsonfv is offline
Registered User
 
Join Date: Apr 2009
Posts: 42
here is a trick to help pass complie for your sp2. in your sp2, write:
IF 1 = 2 THEN
{
DECLARE TEMP TABLE HERE...
}

call your sp1;

the if statement will help you pass compilation, while in run time, the if statement will not execute.
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