游标的最简单结构是:
declare
--定义一个游标
cursor vrows is select * from area where parent_area=340000;
--游标的单列
vrow area%rowtype;
begin
--打开游标
open vrows;
--循环
loop
--注入,相当于for循环
fetch vrows into vrow;
--结束条件
exit when vrows%notfound;
--输出
dbms_output.put_line('地市:'||vrow.name);
--退出循环
end loop;
--关闭游标
close vrows;
end;
这种思路是这样的,先定义游标,再循环游标,当然还有更方便的写法
declare
--定义一个游标
cursor vrows is select * from area where parent_area=340000;
--游标的单列
vrow area%rowtype;
begin
--注入,相当于for循环
for vrow in vrows loop
--输出
dbms_output.put_line('地市:'||vrow.name);
end loop;
end;