日期:2014-05-17  浏览次数:20703 次

求一个删除的存储过程,谢谢
删除表中符合条件的数据,达到1000条时候提交一次,一直到符合条件的删除为止

create   or   replace   procedure   del_guest(indate   in   varchar2)   is
begin
    .....

end   del_guest;

谢谢

------解决方案--------------------
begin
i:=0;
for v in ... loop
delete ...
i:=i+1;
if i=1000 then
commit;
i:=0;
end if;
end loop;
commit;--最后一批不够1000的一起commit;
end ;
------解决方案--------------------
set serveroutput on size 100000
set timing on
declare
type typ1 IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
rec_tab typ1;
CURSOR c1 IS SELECT rowid from TABLE1 where startdate <sysdate-30 and status= 'S ';
i number;
j number;
k number;
begin
OPEN c1;
loop
FETCH c1 BULK COLLECT INTO rec_tab LIMIT 1000;
i := c1%ROWCOUNT;
exit when not rec_tab.EXISTS(1);
forall j in rec_tab.FIRST..rec_tab.LAST
delete TABLE1 where rowid=rec_tab(j);
k := SQL%ROWCOUNT;
dbms_output.put_line( 'delete '||k|| ' rows ');
commit;
exit when c1%notfound;
end loop;
close c1;
dbms_output.put_line( 'total: delete '||i|| ' rows ');
end;
/