我创建了以下作业
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 :(得分:0)
感谢您抽出时间研究我的问题并提出解决方法。实际上我只是在job_action属性中添加了模式名称,并且作业正常运行。