SQL 异常 ORA-27478:作业 "JOB_MIG_17602" 在 DBMS_SCHEDULER.run_job 期间是 运行

SQL Exception ORA-27478: job "JOB_MIG_17602" is running during DBMS_SCHEDULER.run_job

尝试并行 运行 多个作业时出现以下异常。这间歇性地发生。

失败点是DBMS_SCHEDULER.run_job

SQL Exception ORA-27478: job "JOB_MIG_17602" is running
"ORA-06512: at "SYS.DBMS_ISCHED", line 196
ORA-06512: at "SYS.DBMS_SCHEDULER", line 48

职位描述:

作业调用更新 table 的存储过程。使用唯一作业名称创建的作业的不同实例调用相同的存储过程。

以下是 运行 作业的步骤:

DBMS_SCHEDULER.create_job(
    job_name                     => l_job_name,
    job_type                     => 'STORED_PROCEDURE',
    job_action                   => i_chunk_processor_name,
    number_of_arguments          => 2,
    enabled                      => FALSE,
    auto_drop                    => FALSE
);

DBMS_SCHEDULER.set_job_argument_value(job_name => l_job_name, argument_position => 1, argument_value => i_user_id);

DBMS_SCHEDULER.set_job_argument_value(job_name => l_job_name, argument_position => 2, argument_value => i_chunk_id);


DBMS_SCHEDULER.enable(l_job_name);

COMMIT;

DBMS_SCHEDULER.run_job(job_name => l_job_name, use_current_session => FALSE);

启用作业意味着它有资格执行。因此,如果调度程序协调器在 之前选择并启动它,您将获得 "run_job" 命令,那么您将收到错误,例如

SQL> begin
  2    DBMS_SCHEDULER.create_job(
  3      job_name                     => 'XXX',
  4      job_type                     => 'PLSQL_BLOCK',
  5      job_action                   => 'begin dbms_lock.sleep(60); end;',
  6      enabled                      => FALSE,
  7      auto_drop                    => FALSE
  8  );
  9  end;
 10  /

PL/SQL procedure successfully completed.

SQL> exec DBMS_SCHEDULER.enable('XXX');

PL/SQL procedure successfully completed.

-- I wait for a few seconds
--
SQL> exec DBMS_SCHEDULER.run_job(job_name => 'XXX', use_current_session => FALSE);
BEGIN DBMS_SCHEDULER.run_job(job_name => 'XXX', use_current_session => FALSE); END;

*
ERROR at line 1:
ORA-27478: job "MCDONAC"."XXX" is running
ORA-06512: at "SYS.DBMS_ISCHED", line 238
ORA-06512: at "SYS.DBMS_SCHEDULER", line 568
ORA-06512: at line 1

如果您要启用它,则不需要明确的 run_job 请求。