set serveroutput ondeclared cursor cur is select id,status from 表名 where rownum<=100 and type='给定值' and status='1' for update; begin for rec in cur loop update 表名 set status='2' where current of cur; dbms_output.put_line('更新的id为:['id']'); end loop; end; /
create or replace procedure test_upd( in_type i 表名.id%TYPE, o_idlst o varchar2 )as cur sys_refcursor; rec 表名%ROWTYPE; begin open cur for select id,status from 表名 where rownum<=100 and type= in_type and status='1' for update; loop fetch cur into rec; exit when cur%NOTFOUND; update 表名 set status='2' where id = rec.id; o_idlst := o_idlst+","; end loop; close cur; end; /
in_type i 表名.id%TYPE, o_idlst o varchar2 改为 in_type in 表名.id%TYPE, o_idlst out varchar2
set serveroutput ondeclared
cursor cur is
select id,status
from 表名
where rownum<=100
and type='给定值'
and status='1'
for update;
begin
for rec in cur loop
update 表名 set status='2' where current of cur;
dbms_output.put_line('更新的id为:['id']');
end loop;
end;
/
in_type i 表名.id%TYPE,
o_idlst o varchar2
)as
cur sys_refcursor;
rec 表名%ROWTYPE;
begin
open cur for
select id,status
from 表名
where rownum<=100
and type= in_type
and status='1'
for update;
loop
fetch cur into rec;
exit when cur%NOTFOUND;
update 表名 set status='2' where id = rec.id;
o_idlst := o_idlst+",";
end loop;
close cur;
end;
/
o_idlst o varchar2
改为
in_type in 表名.id%TYPE,
o_idlst out varchar2