i、使用for循环来使用cursor:
declare
cursor cur is select * from t_user where age = 22;
userinfo t_user%rowtype;
begin
for userinfo in cur loop
exit when cur%notfound;
dbms_output.put_line('user id : ' || userinfo.id || '-' || 'user name : ' || userinfo.username);
end loop;
exception
when others then
dbms_output.put_line(sqlerrm);
end;
ii、使用fetch来使用cursor: exp2
declare
cursor cur is select * from t_user where age = 22;
userinfo t_user%rowtype;
begin
open cur;
loop
exit when cur%notfound;
fetch cur into userinfo;
dbms_output.put_line('user id : ' || userinfo.id || '-' || 'user name : ' || userinfo.username);
end loop;
exception
when others then
dbms_output.put_line(sqlerrm);
close cur;
end;