sql >> データベース >  >> RDS >> Oracle

毎日スケジュールされたジョブでオラクルのストアドプロシージャを呼び出す方法は?

    ああ、あなたのコードはとても複雑に見えます。最初にこの単純化を検討してください:

    CREATE OR REPLACE PROCEDURE Archive 
    IS
       v_query varchar2(2048);
    BEGIN 
        FOR REC IN (select tablename,columnname condition from pseb.purge_tables)
        LOOP
           if(rec.tablename ='cfw.DCTBLPERFCUMULATIVEMASTER') then
               v_query:='delete from cfw.DCTBLPERFDCUMULATIVEB3MAINREG where cumulativeid in (select cumulativeid FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
               v_query:='delete from cfw.DCTBLPERFDCUMULATIVEB4TODENERG where cumulativeid in (select cumulativeid FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
               v_query:='delete from cfw.DCTBLPERDFCUMULATIVEB5MAXDEMAN where cumulativeid in (select cumulativeid FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
               v_query:='delete from cfw.DCTBLPERFDCUMULATIVEB6TODREG where cumulativeid in (select cumulativeid FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
               v_query:='delete from cfw.DCTBLPERFDCUMULATIVEB7MAXDEMAN where cumulativeid in (select cumulativeid FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
               v_query:='delete from cfw.DCTBLPERFDCUMULATIVEB8MAXDEMAN where cumulativeid in (select cumulativeid FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
               v_query:='delete FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
           else
               v_query:='delete FROM '|| rec.tablename || ' WHERE ' || rec.condition||' < sysdate-90';
               execute immediate v_query;
           end if;
        END LOOP;
    END; --Procedure
    

    dbms_job.submit による代替ジョブ定義:

    declare 
     jid number;
    begin
    dbms_job.submit(
        JOB => jid,
        WHAT => 'pseb.archive;', 
        NEXT_DATE => SYSDATE, 
        INTERVAL  => 'sysdate +2');
    end;
    /
    commit; -- <<--added commit here
    

    ジョブを確認する方法:

    select * from user_jobs;
    


    1. Oracleテーブルから値カウントを取得する

    2. PostgreSQL接続プール:パート2 – PgBouncer

    3. SQL Server(T-SQL)で現在のセッションの言語を取得する3つの方法

    4. Oracle、PostgreSQL、SQLServerでタイムスタンプを比較する一般的な方法