游标的作用就是用于临时存储从数据库中提取的数据块
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;
本文深入解析了SQL游标的作用及其在数据库数据检索中的应用,包括使用LOOP循环和FOR...IN...LOOP循环来遍历游标获取数据,并在遍历结束后正确关闭游标以释放资源。
6770

被折叠的 条评论
为什么被折叠?



