游标的作用就是用于临时存储从数据库中提取的数据块
1、loop循环取游标的值
--定义游标
declare
cursor test_cursor is
select * from t_pstu_reginfo where rownum<10;
tab test_cursor%rowtype;---定义游标变量
begin
open test_cursor;
loop
fetch test_cursor into tab;
exit when test_cursor%notfound;
dbms_output.put_line(tab.zjhm);
end loop;
if test_cursor%isopen then
close test_cursor;
end if;
end;
2、for.. in ...loop 循环取游标的值
declare
cursor test_cursor is
select * from t_pstu_reginfo where rownum<10;
begin
for tab in test_cursor loop
dbms_output.put_line(tab.zjhm);
end loop;
exception
when others then
dbms_output.put_line('error');
if test_cursor%isopen then
close test_cursor;
end if;
end;