title: Passing different (multiple) cursors to the same For Loop
body: <p>Edited for better clarification: </p>
  
  <hr>
  
  <p>Added 1/28/09:  I over simplified the code to make it easy to explain, but the select statements are very long and complicated, and the second one is dependent on the first meaning after the first cursor is done and looped through and the inserts are created the second select actually looks at the first inserts as part of the where clause.</p>
  
  <p>This is why I need to use the loop more then once and not combine the selects in any way.
  I need them to run when I call them in the order I want to call them, which brings me back to my original question is there anyway to re-use a loop with a different cursor?</p>
  
  <p>Thanks again.</p>
  
  <hr>
  
  <p>I am creating a package (Oracle 10) in which I have 4 different select statements (possibly more to come) all of which I create a cursor for and get my data.  Now usually I take the data and create a For Loop and all is well.</p>
  
  <p>My problem is that I have 4 different selects but I want to re-use the loop so that I can have cursor c2 utilize the same loop as well as c3, and c4.  All of which are cursors getting different information from very different selects but they are all going into the same table with my insert statement in the loop.  Also I cannot join all the selects together, they have to be done in order with a commit after each loop  </p>
  
  <p>I created an example below with 4 loops but as you can see they are all the same, the only difference is :  For r in c1 loop,  For r in c2 loop ...
  I think there must be someway to reuse the loop.  I had a few ideas none of which worked. </p>
  
  <pre><code> cursor c1 is  select info_a, info_b from table_x where info_g = 77; 
   cursor c2 is  select info-a, info_b from table_x where info_g = 88;
   cursor c3 is  select info-a, info_b from table_y where info_j = 88;
   cursor c4 is  select info-a, info_b from table_y where info_j = 99;
  
  
    Begin
  
       For r in c1 loop
          insert into fun_table (good_info, boring_info) values (r.info_a, r.info-b);
       end loop;
      commit;
  
       For r in c2 loop
          insert into fun_table (good_info, boring_info) values (r.info_a, r.info-b);
       end loop;
      commit;
  
       For r in c3 loop
          insert into fun_table (good_info, boring_info) values (r.info_a, r.info-b);
       end loop;
      commit;
  
       For r in c4 loop
          insert into fun_table (good_info, boring_info) values (r.info_a, r.info-b);
       end loop;
      commit;
  
     end;
  </code></pre>
  
  <p>Hope this makes more sense and thanks </p>
  
  <p>I edited and then some answers came in.. sorry.
  The original looked something like this:</p>
  
  <pre><code> cursor c1 is  select some_info, other_info from some_table where where some_thing = 'xyz'; 
  cursor c2 is select some_info, other_info from some_table where where some_thing = 'abc';
  
     For r in c1 loop
          insert into fun_table (good_info, boring_info) values (r.some_info, r.other_info);
      end loop;
  </code></pre>