首页 > 技术文章 > ORALCE 游标简单的实例

champaign 2016-09-18 16:49 原文

--取简单的游标

declare 
   cursor sp is 
   select * from user_tables;   
   myrecord user_tables%ROWTYPE;
begin
   open sp ;
   fetch sp into myrecord;
   while sp%found loop
     dbms_output.put_line(myrecord.table_name);   
     fetch sp into myrecord;
   end loop;
   close sp ;  
end;

--带参数的游标

declare 
   cursor sp(rownum number) is 
   select * from user_tables a where a.NUM_ROWS>=rownum;   
   myrecord user_tables%ROWTYPE;
begin
   open sp(10000) ;
   fetch sp into myrecord;
   while sp%found loop
     dbms_output.put_line(myrecord.table_name);   
     fetch sp into myrecord;
   end loop;
   close sp ;  
end;

--隐性游标

begin
   for sp in  (select * from user_tables) loop
     dbms_output.put_line(sp.table_name);   
   end loop;
end;

 

推荐阅读