欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

oracle语法备忘-游标

程序员文章站 2022-03-13 10:29:58
...

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;