oracle的游标备忘
显示游标
declare
cursor cur_sel is select t.month_id,t.prov_id from table t where rownum < 100;
var_1 table.Month_Id%type;
var_2 table.Prov_Id%type;
begin
open cur_sel;
loop
fetch cur_sel into var_1,var_2;
exit when cur_sel%notfound;
dbms_output.put_line(var_1||' '||var_2);
end loop;
close cur_sel;
end;
动态游标
declare
type mytype is ref cursor;
mycur mytype;
var_1 table.Month_Id%type;
var_2 table.Prov_Id%type;
begin
open mycur for select t.month_id,t.prov_id from table t where rownum < 100;
loop
fetch mycur into var_1,var_2;
exit when mycur%notfound;
dbms_output.put_line(var_1||' '||var_2);
end loop;
close mycur;
end;
本文介绍了Oracle数据库中游标的使用方法,包括显示游标与动态游标的声明与操作流程。通过具体的PL/SQL代码示例展示了如何打开游标、获取数据及关闭游标,适用于初学者了解并掌握Oracle游标的基本用法。
255

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



