zoukankan      html  css  js  c++  java
  • 使用for循环,批量删除历史数据

    declare
      maxrows number default 500000;
    begin
      for i in 1 .. 100 loop
        delete from TB_OPT_LOG
         where op_time < to_date('20181001', 'yyyy-mm-dd')
           and rownum <= maxrows;
        commit;
      end loop;
    end;
    create or replace procedure test as
     cursor delete_cursor is select table_name from dba_tables where owner='SCOTT' and table_name in('OBJ1','OBJ2');
     V_TABLE_NAME dba_tables.table_name%type;
     BEGIN open delete_cursor;
      fetch delete_cursor into v_table_name;
       IF v_table_name= 'OBJ1' THEN
      for i in 1 .. 100 loop
        delete from scott.OBJ1
         where CREATED < to_date('20181001', 'yyyy-mm-dd')
           and rownum <= 500000;
        commit;
      end loop;
     elsif v_table_name = 'OBJ2' then
      for i in 1 .. 100 loop
        delete from scott.OBJ2
         where CREATED < to_date('20191001', 'yyyy-mm-dd')
           and rownum <= 500000;
        commit;
      end loop;
     close delete_cursor;
     end if;
     end;
     declare
      job number;
    BEGIN
      DBMS_JOB.SUBMIT(  
            JOB => job,  /*自动生成JOB_ID*/  
            WHAT => 'delete_log;',  /*需要执行的存储过程名称或SQL语句*/ 
            NEXT_DATE => sysdate,  /*初次执行时间-立即执行*/  
            INTERVAL => 'TRUNC(sysdate+1)+1/24' /*每天凌晨一点执行一次*/
          );  
    --commit;
    end;     
    /
  • 相关阅读:
    poj3292
    poj2635
    Android学习之——自己搭建Http框架(2)——框架扩展
    swift -函数、函数指针
    算法导论 第二十一章:不相交集合森林
    Java推断类和实例的关系
    深搜解Riding the Fences
    mariadb克隆
    java-集合类(二)
    在GitHub上使用Hexo搭建静态博客
  • 原文地址:https://www.cnblogs.com/lvcha001/p/11691039.html
Copyright © 2011-2022 走看看