SunQuest
           DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old July 25th, 2005, 05:47 AM
Supriyo Supriyo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 2 Supriyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 50 sec
Reputation Power: 0
Using GLOBAL TEMPORARY TABLE and CURSOR

I have a requirement where I have to populate a TEMPORARY TABLE and use the table in a CURSOR.

In a stored procedure it is mandatory to declare the CURSOR before I declare the the TEMPORARY TABLE. But it gives me an error:
"SESSION.TABLE_NAME" is an Undefined Name.

Following is the code:

CREATE PROCEDURE CORE.TEMP_TABLE_SP ( )
DYNAMIC RESULT SETS 1
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN

DECLARE TEMP CURSOR FOR
SELECT * FROM SESSION.TEMP_SERVICE;

DECLARE GLOBAL TEMPORARY TABLE TEMP_SERVICE (ID_NUM INT) WITH REPLACE NOT LOGGED;

Delete from session.TEMP_SERVICE;

Insert into session.TEMP_SERVICE
VALUES(2);

OPEN TEMP;
END P1

Can any body help me?......

Reply With Quote
  #2  
Old July 25th, 2005, 10:03 AM
fractalvibes fractalvibes is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Location: Waco, Texas
Posts: 632 fractalvibes User rank is Sergeant (500 - 2000 Reputation Level)fractalvibes User rank is Sergeant (500 - 2000 Reputation Level)fractalvibes User rank is Sergeant (500 - 2000 Reputation Level)fractalvibes User rank is Sergeant (500 - 2000 Reputation Level)fractalvibes User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 14 h 11 m 13 sec
Reputation Power: 22
I would think that you should declare and populate the global temp table first

fv


Quote:
Originally Posted by Supriyo
I have a requirement where I have to populate a TEMPORARY TABLE and use the table in a CURSOR.

In a stored procedure it is mandatory to declare the CURSOR before I declare the the TEMPORARY TABLE. But it gives me an error:
"SESSION.TABLE_NAME" is an Undefined Name.

Following is the code:

CREATE PROCEDURE CORE.TEMP_TABLE_SP ( )
DYNAMIC RESULT SETS 1
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN

DECLARE TEMP CURSOR FOR
SELECT * FROM SESSION.TEMP_SERVICE;

DECLARE GLOBAL TEMPORARY TABLE TEMP_SERVICE (ID_NUM INT) WITH REPLACE NOT LOGGED;

Delete from session.TEMP_SERVICE;

Insert into session.TEMP_SERVICE
VALUES(2);

OPEN TEMP;
END P1

Can any body help me?......
__________________
...because that is the way we have always done it. We've been doing it like that for 80 Years! (How do we change that mindset?)

Reply With Quote
  #3  
Old July 26th, 2005, 01:28 AM
Supriyo Supriyo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 2 Supriyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by fractalvibes
I would think that you should declare and populate the global temp table first

fv

In a Stored Procedure in db2 we can not declare temporary table before we declare the cursor.

Reply With Quote
  #4  
Old March 21st, 2007, 03:44 AM
nemali nemali is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 1 nemali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 0
Quote:
Originally Posted by fractalvibes
I would think that you should declare and populate the global temp table first

fv



Here you go....... try this one it works

CREATE PROCEDURE FETCH_CS01_TEST_RESULTS_PRC1()
RESULT SETS 1
LANGUAGE SQL
P1 : BEGIN


DECLARE GLOBAL TEMPORARY TABLE XYZ(
ID INTEGER);




P2 : BEGIN


DECLARE c1 CURSOR WITH RETURN FOR SELECT ID FROM SESSION.XYZ ;


OPEN c1;

END P2;
END P1@

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > Using GLOBAL TEMPORARY TABLE and CURSOR


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway