Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2008
    Posts
    17

    Unanswered: 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

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  3. #3
    Join Date
    Nov 2007
    Posts
    36
    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;

  4. #4
    Join Date
    Jul 2008
    Posts
    17
    Thank you all very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •