create package my as type curtype is ref cursor return test%ROWTYPE; procedure open_cv( cur_cv in out curtype); end;create or replace package body my as procedure open_cv(cur_cv in out curtype) as v_f1 number(10); cursor cur_cv1 is select f1 from test where f1>1 for update; begin open cur_cv1; fetch cur_cv1 into v_f1; while(cur_cv1%found) loop update t1 set f1 = f1 + 1 where current of cur_cv1; fetch cur_cv1 into v_f1; end loop; close cur_cv1;
open cur_cv for select f1 from test where f1>1; end; end; /需要说明的是,游标的方向是单向的,每次fetch就往前进了一步,是不能往后退的,所以,这里先定义一个游标完成你需要的更新操作。更新操作做完以后,再打开一个游标返回。
type curtype is ref cursor return test%ROWTYPE;
procedure open_cv( cur_cv in out curtype);
end;create or replace package body my as
procedure open_cv(cur_cv in out curtype)
as
v_f1 number(10);
cursor cur_cv1 is select f1 from test where f1>1 for update;
begin
open cur_cv1;
fetch cur_cv1 into v_f1;
while(cur_cv1%found)
loop
update t1 set f1 = f1 + 1 where current of cur_cv1;
fetch cur_cv1 into v_f1;
end loop;
close cur_cv1;
open cur_cv for select f1 from test where f1>1;
end;
end;
/需要说明的是,游标的方向是单向的,每次fetch就往前进了一步,是不能往后退的,所以,这里先定义一个游标完成你需要的更新操作。更新操作做完以后,再打开一个游标返回。
有没有不用查询两次的方法呢?
比如不用fetch将一个游标内容复制给另一个游标呢?