If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Cursor within a cursor in DB2?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-08, 15:26
blackhawk_123 blackhawk_123 is offline
Registered User
 
Join Date: Jul 2008
Posts: 17
Cursor within a cursor in DB2?

Hi all,

Can anyone give me an example of how to open a cursor within a cursor?

If you having working example, can you please post?

Thank you all
Reply With Quote
  #2 (permalink)  
Old 08-18-08, 16:55
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Cursors are independent from each other. Just open the 2nd cursor and feed any host variables to it that you like.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 08-19-08, 10:20
ani_dbforum ani_dbforum is offline
Registered User
 
Join Date: Nov 2007
Posts: 32
Please fine below code for opening one cursor under another cursor.
I may be missing some syntax but the idea is similar.




open cursor1;
fetch cursor1
into v_p_id,v_o_id,v_e_count;


set p_stat1=SQLSTATE;
if ( p_stat1 = '02000') then
set loop2 = 1;
end if;

while (loop2 = 0) do

open cursor2;
fetch cursor2
into v_set_id,v_episode_count_by_set;

set p_stat2=SQLSTATE;
if ( p_stat2 = '02000' ) then
set loop3=1;

while(loop3=0) do

set of statements....

fetch cursor2 into ...

end while ;
close cursor1;
fetch cursor1 into ...;
close cursor2;
end while;
Reply With Quote
  #4 (permalink)  
Old 08-21-08, 18:14
blackhawk_123 blackhawk_123 is offline
Registered User
 
Join Date: Jul 2008
Posts: 17
Thank you all very much.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On