declare 
cursor cursor_test
is select * from bss_epon_interface where rownum<10
 --where area_id like  '%01'
;
type cursor_test_tab is table of bss_epon_interface%rowtype;
cursor_test_id  cursor_test_tab;
begin 
open cursor_test;
loop 
 fetch cursor_test bulk collect into cursor_test_id   limit 1 ;
 
 for  i in 1..cursor_test_id.count loop
    
   dbms_output.put_line(I||'AREA_ID'||cursor_test_id(I).orderid||
      'AREA_FATHERID'||CURSOR_TEST_ID(i).areaid);
        exit when  cursor_test%notfound;
 
  end loop ;
          exit when  cursor_test%notfound;
  end loop ;
  close cursor_test;
  end; 游标  循环  跳出

解决方案 »

  1.   

    对跳出游标,以上exit when  cursor_test%notfound 跳出是什么原理呢有什么区别!
      

  2.   

    declare 
    cursor cursor_test
    is select * from bss_epon_interface where rownum<10
     --where area_id like  '%01'
    ;
    type cursor_test_tab is table of bss_epon_interface%rowtype;
    cursor_test_id  cursor_test_tab;
    begin 
    open cursor_test;
    loop 
     fetch cursor_test bulk collect into cursor_test_id   limit 2 ;
     exit when  cursor_test%notfound;---当跳出游标放这里的时候,没循环完就跳出了呢
     for  i in 1..cursor_test_id.count loop
        
       dbms_output.put_line(I||'AREA_ID'||cursor_test_id(I).orderid||
          'AREA_FATHERID'||CURSOR_TEST_ID(i).areaid);
             
     
      end loop ;
          
      end loop ;
      close cursor_test;
      end; 
      

  3.   


    declare
      cursor cursor_test is
        select *
          from bss_epon_interface
         where rownum < 10
        --where area_id like  '%01'
        ;
      type cursor_test_tab is table of bss_epon_interface%rowtype;
      cursor_test_id cursor_test_tab;
    begin
      open cursor_test;
      loop
        fetch cursor_test bulk collect 
          into cursor_test_id limit 1; --cursor_test每次仅抓取一条记录
      
        for i in 1 .. cursor_test_id.count loop
        
          dbms_output.put_line(I || 'AREA_ID' || cursor_test_id(I).orderid ||
                               'AREA_FATHERID' || CURSOR_TEST_ID(i).areaid);
          exit when cursor_test%notfound; -- 读完一条记录就退出,重新进入循环抓取一条记录
        
        end loop;
        exit when cursor_test%notfound; --读完所有游标数据退出整个循环
      end loop;
      close cursor_test;
    end;
      

  4.   

    二重循环  里面那个用于内层的for循环   外面用于普通的loop循环