启用和禁止Oracle的dbms_job

在我们不想让某个job运行时,可将其禁用,通过调用dbms_job.broken完成。

 

dbms_job.broken过程的语法为:

dbms_job.broken(

    job         in binary_integer,

    broken      in boolen,

    next_date   in date default sysdate);

 

因此在调用过程broken时,至少需要提供两个参数:job和broken,next_date通常默认采用缺省值。broken值为true时,表示禁用job;false时,表示启用job。如下命令将禁用job 341:

 

SQL> exec dbms_job.broken(341,true);

 

PL/SQL procedure successfully completed.

 

注意,执行dbms_job.broken过程时,登录用户需为job属主。否则会出现下列错误:

 

$ sqlplus ‘/as sysdba’

SQL> exec dbms_job.broken(287,true);

BEGIN dbms_job.broken(287,true); END;

 

*

ERROR at line 1:

ORA-23421: job number 287 is not a job in the job queue

ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86

ORA-06512: at "SYS.DBMS_IJOB", line 529

ORA-06512: at "SYS.DBMS_JOB", line 245

ORA-06512: at line 1

 

启用已被禁用的job,通过如下命令:

 

SQL> exec dbms_job.broken(341,false);

 

PL/SQL procedure successfully completed.

你可能感兴趣的:(启用和禁止Oracle的dbms_job)