DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

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:
  #1  
Old July 25th, 2005, 06: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, 11:03 AM
fractalvibes fractalvibes is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Location: Waco, Texas
Posts: 636 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 16 h 10 m 47 sec
Reputation Power: 25
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, 02: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, 04: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
  #5  
Old April 4th, 2010, 01:01 AM
pravnibm pravnibm is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 1 pravnibm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 34 sec
Reputation Power: 0
Thanks.. This helped me also..

Reply With Quote
  #6  
Old June 16th, 2010, 04:02 PM
rawasi rawasi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 1 rawasi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 5 sec
Reputation Power: 0
Hi, wonderful tip. We were stuck trying to use a temporary table with a cursor, until we read in this thread that you have to declare the cursr first and then the global temporary table.

Thanks!

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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap