日期:2014-05-17  浏览次数:20825 次

为什么用while循环提取不了游标,用loop就可以?
SQL code

declare
   cursor e is select * from emp ;  
   e_row emp%rowtype;               
begin
   open e ;                      
   loop       --用这种方式可以
       exit when e%notfound;         
       fetch e into e_row ;           
       dbms_output.put_line( rpad(e_row.ename , 15 , ' ') || '  ' || e_row.sal);
   end loop;
   close e;                     
end;




SQL code

declare
   cursor e is select * from emp ;  
   e_row emp%rowtype;               
begin
   open e ;                      
   while e%found loop     --这种方式就没用,控制台不打印
       fetch e into e_row ;           
       dbms_output.put_line( rpad(e_row.ename , 15 , ' ') || '  ' || e_row.sal);
   end loop;
   close e;                     
end;




------解决方案--------------------
declare
cursor e is select * from emp ;
e_row emp%rowtype;
begin
open e ; 
fetch e into e_row ;
while e%found loop --这种方式就没用,控制台不打印
dbms_output.put_line( rpad(e_row.ename , 15 , ' ') || ' ' || e_row.sal);
fetch e into e_row ;
end loop;
close e;
end;