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;