IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 - Update a table inside a Cursor


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
subramsa

New User


Joined: 15 Apr 2005
Posts: 16
Location: Bangalore, India

PostPosted: Tue May 26, 2009 11:48 am
Reply with quote

Assume that i have a table
DEV.EMPLOYEE TABLE which contains
GEO_CODE CHAR(2)
COUNTRY_CODE CHAR(3)
EMP_NO CHAR(7)
EMP_NAME CHAR(40)
SALARY DEC(15,2)

DECLARE C1 CURSOR FOR SELECT GEO_CODE, COUNTRY, EMP_NO, EMP_NAME, SALARY FROM DEV.EMPLOYEE WHERE GEO_CODE = 'AP'

OPEN C1

FETCH C1

Then i am doing following Update inside the CURSOR loop

UPDATE DEV.EMPLOYEE SET SALARY = SALARY + 100 where COUNTRY = '744';

Now my question is
when we declare the cursor and open it, does the records qualified for the cursor are transferred to temp memory area?
can i update/delete the same table which are declared in the cursor inside the FETCH loop
after the UPDATE or DELETE inside the fetch operation where will be cursor pointer

icon_rolleyes.gif
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue May 26, 2009 1:32 pm
Reply with quote

Quote:

when we declare the cursor and open it, does the records qualified for the cursor are transferred to temp memory area?


Its not physical transfer ....

Quote:

can i update/delete the same table which are declared in the cursor inside the FETCH loop

Absolutely YES ...

Quote:

after the UPDATE or DELETE inside the fetch operation where will be cursor pointer

The current row which was fetched ....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue May 26, 2009 4:36 pm
Reply with quote

are you issuing any COMMIT's during this process.
How many times are you executing the SQL to update where COUNTRY = '744'?
Quote:
when we declare the cursor and open it, does the records qualified for the cursor are transferred to temp memory area?

A simple answer to your question will not make you conversant with the technical details.
Suggest that you read the Application Programmers SQL Guide for your site's version of DB2; there is a very good discussion about cursors.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue May 26, 2009 4:40 pm
Reply with quote

Quote:
UPDATE DEV.EMPLOYEE SET SALARY = SALARY + 100 where COUNTRY = '744';



I do not see anywhere the update/query related to the cursor processing

for employees with country code 744 the salary will be raised by ( 100 * number of iterations )

It would be wise to provide better details to clarify the sequence of fetch/updates/.....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top