删除表中符合条件的数据,达到1000条时候提交一次,一直到符合条件的删除为止create or replace procedure del_guest(indate in varchar2) is
begin
  .....end del_guest;谢谢

解决方案 »

  1.   

    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 ;
      

  2.   

    谢谢各位,我想这样做
    delete from 表 where g_indate >indate(参数) and rownum<1000;
    commit;一直到符合条件的删除为止create or replace procedure del_guest(indate in varchar2) is
    begin
      end del_guest;
      

  3.   

    create or replace procedure del_guest(indate in varchar2) is
    pragma autonomous_transaction;
    begin
    while 1=1 loop
     EXECUTE IMMEDIATE
     'delete from hn_guest where rownum <= :rn' USING 1000;
    if SQL%NOTFOUND then
     exit;
    end if;
    commit;
    end loop;
    end;
    对吗??
      end del_guest;
      

  4.   

    你要删除多少记录啊,这样删除很耗时啊,又不是insert
      

  5.   

    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;
    /
      

  6.   

    to hongqi162(失踪的月亮)
    那有什么好方法啊,介绍下吗