我在一个存储过程里定义了一个cursor 我怎样才能重复的循环这个cursor。
我的程序是这样:
cursor cur1;
cursor cur2;open cur1;
loop
    fetch cur1 into v1;
    exit when cur1%notfound;
    open cur2;
    loop
       fetch cur2 into v2;
       exit when cur2%notfound;
       --do something
    end loop
    close cur2;
end loop;
不知道这样行不行,如果不行应该怎样做

解决方案 »

  1.   

    SQL> declare cursor cur1 is select id from tab_1 ;
      2  cursor cur2(tid tab_1.id%type) is select name from tab_10 where id = tid;
      3  v1 cur1%rowtype;
      4  v2 cur2%rowtype;
      5  begin
      6  open cur1;
      7  loop
      8    fetch cur1 into v1;
      9    exit when cur1%notfound;
     10    open cur2(v1.id);
     11    loop
     12      fetch cur2 into v2;
     13      exit when cur2%notfound;
     14      dbms_output.put_line('----------'||v2.name);
     15    end loop;
     16    close cur2;
     17  end loop;
     18  close cur1 ;
     19  end  ;
     20  /----------trg
    ----------tt2
    ----------tt3
    ----------tt4
    ----------xiaPL/SQL procedure successfully completed