Oracle:执行Job dbms_scheduler

时间:2017-09-08 14:55:29

标签: sql oracle oracle12c job-scheduling dbms-scheduler

我想在Oracle Database 11g快捷版11.2.0.2.0版中执行调度程序 - 64位生产 我有这个包裹:

create or replace PACKAGE  "S_IN_TDK" is


procedure parseMsg;

end;

和这份工作

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
   job_name         =>  'parseMsg',
   program_name     =>  'S_IN_TDK.parseMsg',
   repeat_interval  =>  'FREQ=SECONDLY;INTERVAL=10',
   --job_style        => 'LIGHTWEIGHT',
   comments         => 'Job that polls device n2 every 10 seconds');
END;

但是当我运行这份工作时,我收到了这个错误:

Fallo al procesar el comando SQL
- ORA-27476: "S_IN_TDK.PARSEMSG" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 185
ORA-06512: at "SYS.DBMS_SCHEDULER", line 486
ORA-06512: at line 2

我也试过

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
   job_name         =>  'parseMsg',
   job_action       =>  'begin S_IN_TDK.parseMsg; end;',
   repeat_interval  =>  'FREQ=SECONDLY;INTERVAL=10',
   --job_style        => 'LIGHTWEIGHT',
   comments         => 'Job that polls device n2 every 10 seconds');
END;

然后我收到了这个错误:

 Informe de error -
ORA-06550: line 2, column 3:
PLS-00306: wrong number or types of arguments in call to 'CREATE_JOB'
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

2 个答案:

答案 0 :(得分:3)

参数program_name需要调度程序PROGRAM对象的名称。如果要运行内联程序,请改为使用job_action参数:

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
   job_name         =>  'parseMsg',
   job_action       =>  'begin S_IN_TDK.parseMsg; end;',
   repeat_interval  =>  'FREQ=SECONDLY;INTERVAL=10',
   --job_style        => 'LIGHTWEIGHT',
   comments         => 'Job that polls device n2 every 10 seconds');
END;

请注意job_action需要一个完整的PL / SQL块作为输入。

答案 1 :(得分:2)

DBMS_SCHEDULER.CREATE_JOB有三个必需参数:job_namejob_typejob_action。添加job_type => 'PLSQL_BLOCK',并添加enabled => true,以立即运行作业。

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
   job_name         =>  'parseMsg',
   job_type         =>  'PLSQL_BLOCK',
   job_action       =>  'begin S_IN_TDK.parseMsg; end;',
   repeat_interval  =>  'FREQ=SECONDLY;INTERVAL=10',
   --job_style        => 'LIGHTWEIGHT',
   enabled          =>  true,
   comments         => 'Job that polls device n2 every 10 seconds');
END;
/

使用此查询检查作业状态:

select *
from dba_scheduler_job_run_details
where job_name = 'PARSEMSG'
order by log_date desc;