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

Can we have a Cursor within another Cursor


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

New User


Joined: 26 Sep 2005
Posts: 3

PostPosted: Wed Sep 28, 2005 7:12 pm
Reply with quote

CAN WE GIVE CURSOR WITH IN A CURSOR.THAT I DECLARE A CURSOR C1 ,OPEN IT AND CAN I DECLARE ANOTHER CURSOR C2 AND OPEN IT AND CLOSE C2 AND CLOSE C1.

LIKE NESTED LOOPS NESTED ,CURSORS ARE POSSIBLE OR NOT
Back to top
View user's profile Send private message
learnmf

Active User


Joined: 14 Mar 2005
Posts: 123

PostPosted: Wed Sep 28, 2005 7:20 pm
Reply with quote

Hi friends
correct me if i am wrong.
It can't be possible.
Invalid sntax as open cursor commands exex sql open csr end exec.

Thanks and Regards,
Chandra
Back to top
View user's profile Send private message
krishnaiahc

New User


Joined: 31 Aug 2005
Posts: 21

PostPosted: Fri Oct 28, 2005 6:50 am
Reply with quote

Hai aranganathan,

Your right , your logic will work ...

Thanks,
Krishna
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Fri Oct 28, 2005 11:21 am
Reply with quote

Aranganathan,

Ur logic will work
Back to top
View user's profile Send private message
rtalapaneni

New User


Joined: 20 Mar 2005
Posts: 13
Location: Bangalore

PostPosted: Fri Oct 28, 2005 12:16 pm
Reply with quote

I didnt get ..
Will give example code
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Mon Oct 31, 2005 12:27 pm
Reply with quote

hi friend,
its a difficult thing to have a nested cursors. you can open one cursor process it close it and open another one. this is the procedure
Back to top
View user's profile Send private message
paulstephen

New User


Joined: 20 Oct 2005
Posts: 20
Location: Chennai

PostPosted: Mon Oct 31, 2005 2:17 pm
Reply with quote

Any number of cursors can be open at a point of time.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Mon Oct 31, 2005 2:43 pm
Reply with quote

hi,
then how can the nested cursor will work. any no. of cursors can be opened and it can be closed correspondingly but overriding is not possible na.
check it out.
Eg.
Open c1
open c2

close c2
close c1
will work

open c1
open c2

close c1
close c2
won't work na.
Back to top
View user's profile Send private message
paulstephen

New User


Joined: 20 Oct 2005
Posts: 20
Location: Chennai

PostPosted: Mon Oct 31, 2005 3:12 pm
Reply with quote

The sequence of open and close is not a constrain.
Back to top
View user's profile Send private message
tam

New User


Joined: 02 Nov 2005
Posts: 12
Location: zz

PostPosted: Thu Nov 03, 2005 11:56 am
Reply with quote

though nested cursors can be used in db2 - COBOL program but it affects the program efficiency. there are 3 main steps involved in a cursor - open, fetch and close. out of these the open step requires the maximum overhead and nesting of cursors means that you're opening the inner cursor multiple times for every new records fetched by the outer cursor while the outer cursor is still opened. the more efficient way than using the nested cursors is fetch the records of the outer cursor in an array and execute the inner cursor for every record in the array. thus we can save the overhead of opening 2 cursors simultaneously.
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 Is SQLCODE -811 possible while fetchi... DB2 1
No new posts Restart logic by using cursor name in... DB2 1
No new posts Seeking Resolution for SQKCODE -991 o... DB2 2
No new posts Multiple rows within Cursor when Coun... DB2 14
No new posts Dynamic cursor name in Cobol program COBOL Programming 1
Search our Forums:

Back to Top