简体   繁体   English

使用oracle Scheduler调度时的Sql过程

[英]Pl Sql Procedure handle exception while scheduled using oracle scheduler

I have written a procedure which will be scheduled using Oracle scheduler, and am trying to handle an exception using the following exception block: 我已经编写了一个将使用Oracle调度程序进行调度的过程,并且正在尝试使用以下异常块来处理异常:

EXCEPTION
   WHEN OTHERS THEN
      raise_application_error(-20001,'An error was encountered - '
      || SQLCODE || ' -ERROR- ' || SQLERRM);
END;

I also want to make sure if I use above support team or DBA come to know in case of any exception and they can take appropriate action as well as all the transactions should be rolled back. 我还想确定是否使用我的上述支持团队或DBA,以防万一发生任何异常,他们可以采取适当的措施,并且所有事务都应回滚。

If the only reason for the exception block is to notify the support team - don't do it, since it's completely superfluous. 如果导致异常阻止的唯一原因是通知支持团队-不要这样做,因为它完全是多余的。

Oracle logs the outcome of every job run in the views XX_SCHEDULER_JOB_RUNS / XX_SCHEDULER_JOB_RUN_DETAILS , where XX is one of DBA / ALL / USER (User contains all runs for the currently logged-on user, All contains all runs the currently logged-on user is allowed to see, and DBA (which requires special privileges) contains all runs in the database. Oracle在视图XX_SCHEDULER_JOB_RUNS / XX_SCHEDULER_JOB_RUN_DETAILS记录每个作业运行的结果,其中XX是DBA / ALL / USER (用户包含当前登录用户的所有运行,所有包含当前登录用户的所有运行可以看到,DBA(需要特殊特权)包含数据库中的所有运行。

So all your support team has to do is monitor XX_SCHEDULER_JOB_RUN_DETAILS and check for any entries with status FAILURE . 因此,您的支持团队所需要做的就是监视XX_SCHEDULER_JOB_RUN_DETAILS并检查状态为FAILURE所有条目。

Example

Create a job that always fails, and run it once: 创建一个总是失败的作业,然后运行一次:

begin
  dbms_scheduler.create_job(
      job_name => 'JOB_RAISE_DEMO'
     ,job_type => 'PLSQL_BLOCK'
     ,job_action => 'begin raise_application_error(-20001, ''custom error''); end; '

     ,start_date      => to_timestamp_tz('2015-11-20 13:00:00 Europe/Berlin',
                                         'yyyy-mm-dd hh24:mi:ss tzr')
     ,repeat_interval => null
     ,enabled => TRUE
     ,auto_drop => false);
end;

begin
  dbms_scheduler.run_job('JOB_RAISE_DEMO', use_current_session => false);
end;

Then, check the job status: 然后,检查作业状态:

select log_date, job_name, status, error# 
from user_scheduler_job_run_details 
where job_name = 'JOB_RAISE_DEMO';

This returns: 返回:

LOG_DATE                        JOB_NAME        STATUS  ERROR#
20.11.15 12:35:53,516000 +01:00 JOB_RAISE_DEMO  FAILED  20001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM