Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

inserting a row after reading from CURSOR

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
kalukakkad

New User


Joined: 10 Mar 2005
Posts: 81

PostPosted: Wed Jun 22, 2005 3:46 pm    Post subject: inserting a row after reading from CURSOR
Reply with quote

I have a cursor.say TEST_CUR, to select some rows from a table.
Let's say the cursor returns me 3 rows.
Now, after i FETCH from it the first time ,i am inserting the same row into another table.
After this, on FETCHing the 2nd time from TEST_CUR, the query is executed again and i get the same set of rows with the pointer set to 1st row.

Does that mean INSERT operation is causing some problem to the CURSOR.
Back to top
View user's profile Send private message

Pushpak

New User


Joined: 06 May 2005
Posts: 18

PostPosted: Wed Jun 22, 2005 5:27 pm    Post subject: Re: inserting a row after reading from CURSOR
Reply with quote

Hi,

INSERT will never cause your CURSOR activities. This is very common approach, fetch a record & do the updations on the basis of fetched results.

In your case, are you closing a cursor after reading first record, inserting into the different table and before reading a next record.

Pushpak.
Back to top
View user's profile Send private message
kalukakkad

New User


Joined: 10 Mar 2005
Posts: 81

PostPosted: Thu Jun 23, 2005 8:58 am    Post subject: Re: inserting a row after reading from CURSOR
Reply with quote

Thanks for the reply.
But the current situation is :

I have a cursor.say TEST_CUR, to select some rows from a table.
Let's say the cursor returns me 3 rows.
Now, after i FETCH from it the first time: i do 2 things

1)update some columns of the row fetched
2)and insert the same row into another table.

The cursor is FETCH ONLY as it has joins so can't use FOR UPDATE.

After this, on FETCHing the 2nd time from TEST_CUR, the query is executed again and i get the same set of rows with the pointer set to 1st row.

Is updating the row causing the problem....problem with locs?
Back to top
View user's profile Send private message
EnjoyMF

New User


Joined: 27 May 2005
Posts: 88

PostPosted: Fri Jun 24, 2005 12:35 pm    Post subject:
Reply with quote

hi friend

use static cursor...
Back to top
View user's profile Send private message
j_prameela2000

New User


Joined: 01 Jun 2005
Posts: 28
Location: Chennai

PostPosted: Fri Jun 24, 2005 6:02 pm    Post subject: Re: inserting a row after reading from CURSOR
Reply with quote

Hi,

I hope the cursor should be declared with Update option and in the Update statement we must mention where current of. If I am wrong, please correct me.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Thu Nov 03, 2005 2:32 pm    Post subject: cursor update
Reply with quote

hi frnd,
use this
EXEC SQL
DECLARE C1 CURSOR FOR
SELECT...
FOR UPDATE ....
END-EXEC

hope this works
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am
No new posts Reading data from PS file and send it... rajatbagga All Other Mainframe Topics 18 Fri Sep 23, 2016 12:51 pm
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am
No new posts Reading selected volumes of a multi-v... RickBig JCL & VSAM 6 Wed Jul 13, 2016 7:26 pm
No new posts DB2 Stored Procedure - Dynamic SQL - ... GuyC DB2 2 Wed Feb 17, 2016 5:10 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us