DBMS_SCHEDULER.create_job 自动触发的BUG

Scheduler Job Runs Immediately After Enable When Using PL/SQL-expression (Doc ID 2420041.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 11.2.0.4 to 18.1.0.0.0 [Release 11.2 to 18]

Oracle Database Cloud Schema Service - Version N/A and later

Oracle Database Exadata Cloud Machine - Version N/A and later

Oracle Cloud Infrastructure - Database Service - Version N/A and later

Oracle Database Cloud Exadata Service - Version N/A and later

Information in this document applies to any platform.

SYMPTOMS

A job created using DBMS_SCHEDULER, runs automatically after it is enabled, when REPEAT_INTERVAL is calculated by a function (repeat_interval =>'nextExecution',).

The job runs after it is enabled even if the NEXT_RUN_DATE is in the future.

  1. Create a table named testJobTab

SQL> create table testJobTab ( insertdate date);

  1. Create a procedure to insert into the table

SQL> create or replace procedure testJobinsert

is

BEGIN

insert into testJobTab (insertdate) values ( sysdate);

END;

/

  1. Create a function to calculate the date

SQL> create or replace function nextExecution

return date

is

BEGIN

return trunc(sysdate + 10);

END;

/

  1. make sure the table is empty

SQL> truncate table testJobTab;

  1. Create a job (disabled)

SQL> BEGIN

DBMS_SCHEDULER.create_job (

job_name => 'TESTJOB',

job_type => 'PLSQL_BLOCK',

job_action => 'BEGIN testJobinsert; commit; END;',

start_date => systimestamp at TIME zone 'EUROPE/BERLIN',

repeat_interval => 'nextExecution',

end_date => NULL,

enabled => FALSE,

comments => 'TESTJOB'

);

END;

/

  1. check the table

SQL> select * from testJobTab;

no rows selected

  1. check user_scheduler_jobs

SQL> set lines 300

SQL> col start_date for a50

SQL> col last_start_date for a50

SQL> col next_run_date for a50

SQL> col repeat_interval for a25

SQL> select start_date,run_count,last_start_date,next_run_date,enabled,schedule_type,repeat_interval from user_scheduler_jobs where job_name = 'TESTJOB';

START_DATE RUN_COUNT LAST_START_DATE

NEXT_RUN_DATE

ENABL SCHEDULE_TYP REPEAT_INTERVAL





13-MAR-18 08.45.52.057030 AM EUROPE/BERLIN 0

FALSE PLSQL nextExecution

  1. enable the job

SQL> exec DBMS_SCHEDULER.ENABLE('TESTJOB');

  1. check the table (job started after it was ENABLED)

SQL> select * from testJobTab;

INSERTDATE


13-MAR-2018 07:47:01

  1. check user_scheduler_jobs

There is a difference of 10 days between START_DATE/LAST_START_DATE and NEXT_RUN_DATE. LAST_START_DATE and RUN_COUNT confirms that the job has run.

SQL> select start_date,run_count,last_start_date,next_run_date,enabled,schedule_type,repeat_interval from user_scheduler_jobs where job_name = 'TESTJOB';

START_DATE RUN_COUNT LAST_START_DATE

NEXT_RUN_DATE

ENABL SCHEDULE_TYP REPEAT_INTERVAL





13-MAR-18 08.45.52.057030 AM EUROPE/BERLIN 1 13-MAR-18

08.47.01.342411 AM EUROPE/BERLIN 23-MAR-18 12.00.00.000000 AM +00:00

TRUE PLSQL nextExecution

  1. disable the job

SQL> exec DBMS_SCHEDULER.DISABLE('TESTJOB');

  1. check the table (the job did not run after it was DISABLED)

SQL> select * from testJobTab;

INSERTDATE


13-MAR-2018 07:47:01

  1. check user_scheduler_jobs

No modifications to RUN_COUNT, LAST_START_DATE and NEXT_RUN_DATE.

SQL> select start_date,run_count,last_start_date,next_run_date,enabled,schedule_type,repeat_interval from user_scheduler_jobs where job_name = 'TESTJOB';

START_DATE RUN_COUNT LAST_START_DATE

NEXT_RUN_DATE

ENABL SCHEDULE_TYP REPEAT_INTERVAL





13-MAR-18 08.45.52.057030 AM EUROPE/BERLIN 1 13-MAR-18

08.47.01.342411 AM EUROPE/BERLIN 23-MAR-18 12.00.00.000000 AM +00:00

FALSE PLSQL nextExecution

  1. enable the job again

SQL> exec DBMS_SCHEDULER.ENABLE('TESTJOB');

  1. check the table (notice that the job has run again)

SQL> select * from testJobTab;

INSERTDATE


13-MAR-2018 07:47:01

13-MAR-2018 07:53:32

  1. check user_scheduler_jobs

SQL> select start_date,run_count,last_start_date,next_run_date,enabled,schedule_type,repeat_interval from user_scheduler_jobs where job_name = 'TESTJOB';

START_DATE RUN_COUNT LAST_START_DATE

NEXT_RUN_DATE

ENABL SCHEDULE_TYP REPEAT_INTERVAL





13-MAR-18 08.45.52.057030 AM EUROPE/BERLIN 1 13-MAR-18

08.53.32.442546 AM EUROPE/BERLIN 23-MAR-18 12.00.00.000000 AM +00:00

TRUE PLSQL nextExecution

  1. drop the job

SQL> exec DBMS_SCHEDULER.drop_job ('TESTJOB');

SQL> drop table testJobTab purge;

SQL> drop function nextExecution;

SQL> drop procedure testJobinsert;

If REPEAT_INTERVAL is used with FREQ and INTERVAL (repeat_interval => 'FREQ=Minutely;INTERVAL=30'), the job does not run when is enabled which is the expected behavior.

CHANGES

CAUSE

This is caused by

BUG 27697734 - SCHEDULER JOB RUNS IMMEDIATELY AFTER DISABLE/ENABLE WHEN USING PL/SQL-EXPRESSION

SOLUTION

The BUG 27697734 - is regressed and tracking in Bug 28174090

Bug 28174090 - IMPDP FAILS WITH ORA-12005 WHEN USING JOBS HAVING PL/SQL REPEAT_INTERVAL

Download the Patch 28174090 from MOS and apply the Patch 28174090 to your current release and platform.

相关推荐
dingdingfish7 小时前
JSON 系列之1:将 JSON 数据存储在 Oracle 数据库中
oracle·json·database
dingdingfish12 小时前
JSON 系列之2:JSON简单查询
oracle·json·database·19c·23ai
dazhong201216 小时前
PLSQL 客户端连接 Oracle 数据库配置
数据库·oracle
一行玩python1 天前
sqlite3,一个轻量级的 C++ 数据库库!
开发语言·数据库·c++·oracle·sqlite
潇潇和多客开源1 天前
数据库的数据被清除了,该如何恢复?
数据库·oracle
胖头鱼的鱼缸(尹海文)1 天前
数据库管理-第274期 Oracle Enterprise Manager 24ai新特性一览(20241223)
数据库·oracle
百度智能云技术站2 天前
广告投放系统成本降低 70%+,基于 Redis 容量型数据库 PegaDB 的方案设计和业务实践
数据库·redis·oracle
梦想平凡2 天前
PHP 微信棋牌开发全解析:高级教程
android·数据库·oracle
夏木~2 天前
Oracle 中什么情况下 可以使用 EXISTS 替代 IN 提高查询效率
数据库·oracle