oracle游标使用遍历3种方法

1.for循环遍历

declare
cursor mycur is select * from ct_cust_info;
custInfo ct_cust_info%rowtype;
cou number;
begin
for custInfo in mycur loop
cou:=mycur%rowcount;
dbms_output.put_line(cou);
dbms_output.put_line(custInfo.cust_id);
end loop;
end;

2.while遍历

declare
cursor mycur is select * from ct_cust_info;
custInfo ct_cust_info%rowtype;
begin
open mycur;
fetch mycur into custInfo;
while(mycur%found)loop
dbms_output.put_line(custInfo.cust_id);
fetch mycur into custInfo;
end loop;
end;

3.loop遍历

declare
cursor mycur is select * from ct_cust_info;
custInfo ct_cust_info%rowtype;
begin
open mycur;
loop
fetch mycur into custinfo;
exit when mycur%notfound;
dbms_output.put_line(custInfo.cust_id);
end loop;
end;

原文地址:https://www.cnblogs.com/youlangta/p/6785910.html