2016-09-28 108 views
0

我已經創建了以下工作作業調度問題

begin 
dbms_scheduler.create_job(
    job_name => 'DAILY_BACKUP', 
    job_type => 'STORED_PROCEDURE', 
    job_action => 'DB_BACKUP', 
    start_date => sysdate, 
    repeat_interval => 'FREQ=DAILY; BYHOUR=23', 
    enabled => TRUE, 
    comments => 'Runtime: Every day at 11:00 pm'); 
end; 

可以看我的作業已啓用

select job_name, enabled from user_scheduler_jobs; 
JOB_NAME      ENABL 
------------------------------ ----- 
DAILY_BACKUP     TRUE 

我可以看到執行日誌中user_SCHEDULER_JOB_LOG以及

select log_date, substr(job_name, 1, 30)job_name, owner, status from user_SCHEDULER_JOB_LOG; 
    LOG_DATE                 JOB_NAME                             OWNER       STATUS 
--------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------ ------------------------------ ------------------------------ 
26-SEP-16 11.54.14.755972 PM +00:00           DAILY_BACKUP                            BACKUP       SUCCEEDED 
27-SEP-16 02.02.32.603195 AM +00:00           DAILY_BACKUP                            BACKUP       SUCCEEDED 
27-SEP-16 11.54.14.835203 PM +00:00           DAILY_BACKUP                            BACKUP       SUCCEEDED 

user_scheduler_job_log中的第二行是在手動運行作業時創建的。

但應該已經由過程db_backup更新的表數據不會更新。 當我運行使用

 exec dbms_scheduler.run_job('DAILY_BACKUP'); 

我也做了參數級檢查在處理此URL數量建議手動工作表的數據被更新,會話的數量似乎要被罰款。

https://community.oracle.com/thread/648581

我可能已經失蹤很基本的東西,請指導我什麼是錯我的工作?

這裏是在db_backup

create or replace procedure db_backup as 

cursor cur_listOfTables is 
    select table_name from backuplog where backup_flag = 'Y'; 

    v_truncate_query varchar2(4000); 
v_insert_query varchar2(4000); 
v_current_function varchar2(200); 

v_disable_constraint_success number := 0; 
v_truncate_success number := 0; 
v_insert_success number := 0; 
v_enable_constraint_success number := 0; 

v_schema_to_backup varchar2(50) := 'PRODSCHEMA'; 

begin 

    v_current_function := $$PLSQL_UNIT; 

    v_disable_constraint_success := alter_all_fk_constraints(v_schema_to_backup, 'D'); 

    for backup_rec in cur_listOfTables 
    loop 
    v_truncate_query := 'truncate table ' || backup_rec.table_name; 

    v_insert_query := 'insert into ' || backup_rec.table_name || ' select * from ' || backup_rec.table_name || '@prod'; 

    --v_disable_constraint_success := alter_fk_constraints(backup_rec.table_name, 'D'); 

    if v_disable_constraint_success = 0 then 
      begin 
        execute immediate v_truncate_query; 
        exception 
          when others then 
            log_error(v_current_function, backup_rec.table_name, sqlcode, sqlerrm); 
            v_truncate_success := 1; 
      end; 

      if v_truncate_success = 0 then 
        begin 
          execute immediate v_insert_query; 
          exception 
            when others then 
            log_error(v_current_function, backup_rec.table_name, sqlcode, sqlerrm); 
            v_insert_success := 1; 
        end; 
        if v_insert_success = 0 then 
          update backuplog set last_backup_date = sysdate where table_name = backup_rec.table_name; 
          commit; 
        end if; 
      end if; 

      --v_enable_constraint_success := alter_fk_constraints(backup_rec.table_name, 'E'); 

    end if; 

    --dbms_output.put_line(v_truncate_query); 
    --dbms_output.put_line(v_insert_query); 
end loop; 


    v_enable_constraint_success := alter_all_fk_constraints(v_schema_to_backup, 'E'); 
reset_all_sequences(v_schema_to_backup); 

end; 
+0

您能否提供'db_backup'程序的內容? – JSapkota

+0

Hi @JSapkota我在問題 – Prem

+0

* start_date => sysdate *中添加了db_backup的代碼。也許你需要set * to_timestamp(to_char(sysdate,'dd.mm.yyyy')||'23:00:00','dd.mm.yyyy hh24:mi:ss')* – SkyWalker

回答

0

感謝您的時間來看看我的問題,並提出瞭解決方法的代碼。實際上,我只是在job_action屬性中添加了模式名稱,並且作業正常運行。