Oracle
 sql >> Baza danych >  >> RDS >> Oracle

jak wywołać procedurę składowaną w Oracle z codziennymi zaplanowanymi zadaniami?

Omg, twój kod wygląda na tak skomplikowany. Rozważ najpierw to uproszczenie:

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

Alternatywna definicja pracy według 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

Sposób na sprawdzenie pracy:

select * from user_jobs;


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Nieprawidłowy znak w ciągu zapytania SQL (ORA-00911)

  2. Wyświetlanie wartości LITAGG w komórce na podstawie wartości innej kolumny

  3. Upuść tabelę, jeśli istnieje

  4. ORA-12505, TNS:listener nie zna obecnie identyfikatora SID podanego w deskryptorze połączenia

  5. oci_bind_by_name i do_date PHP/OCI/Oracle