当作业未运行时,Oracle Scheduler停止作业会发出异常

时间:2014-07-28 00:49:06

标签: oracle job-scheduling

当我在这个作业没有运行时尝试在oracle中停止预定作业时,我收到异常。

这可能是正常的,但在我的情况下,我需要在运行某些ddl操作之前停止并禁用该作业。

如果我首先检查作业的状态,则无法保证在检查后不会启动。我不知道它是否清楚。

关于如何进行的任何想法?

由于

1 个答案:

答案 0 :(得分:2)

--Stop and Disable a job.
--Ignore exceptions about job not running, existing, or being unknown, since it's
--possible the job just finished.  This means there won't be an exception even if
--the job name is wrong.
declare
    v_not_running exception;
    v_does_not_exist exception;
    v_unknown_job exception;
    pragma exception_init(v_not_running, -27366);
    pragma exception_init(v_does_not_exist, -27476);
    pragma exception_init(v_unknown_job, -27475);
begin
    begin
        dbms_scheduler.stop_job('TEST_JOB');
    exception when v_not_running or v_does_not_exist or v_unknown_job then null;
    end;

    begin
        dbms_scheduler.disable('TEST_JOB');
    exception when v_not_running or v_does_not_exist or v_unknown_job then null;
    end;
end;
/