今天修改业务时,需要用到Oracle数据库中的工作任务,对创建Job语句进行一下整理,以备参考:
declare job binary_integer; d_begindate date; s_interval varchar2(50); begin d_begindate := to_date('2009-08-14 23:50:00', 'yyyy-mm-dd hh24:mi:ss'); s_interval := 'trunc(sysdate + 1) + 23 / 24'; sys.dbms_job.submit(job, 'prc_test;', d_begindate, s_interval, false, 0, false); commit; end; /
使用代码时,只需对几个变量进行相应修改,并写上需要调用的程序块即可。
在PL/SQL Developer 8中,创建JOB与原来区别很大。
1.查询JOB信息
select t.job_name, t.job_type, t.job_action, to_char(t.start_date, 'yyyy-mm-dd hh24:mi:ss'), t.repeat_interval, t.enabled, t.state, to_char(t.last_start_date, 'yyyy-mm-dd hh24:mi:ss') from user_scheduler_jobs t;
2.删除JOB信息
BEGIN SYS.DBMS_SCHEDULER.DROP_JOB (job_name => 'APPS.JOB_MOSS_DELETE_TEMP_TABLE'); END;
3.创建JOB信息
begin sys.dbms_scheduler.create_job(job_name => 'APPS.JOB_MOSS_DELETE_TEMP_TABLE', job_type => 'STORED_PROCEDURE', job_action => 'pkg_bosun_moss_erp.prc_clear_temp_table', number_of_arguments => 3, start_date => to_date('2011-07-18 04:00:00', 'yyyy-mm-dd hh24:mi:ss'), repeat_interval => 'TRUNC(sysdate + 1) + 4 / 24', end_date => null, job_class => 'DEFAULT_JOB_CLASS', enabled => false, auto_drop => false, comments => '每天凌晨4点执行清空销售平台临时表数据'); sys.dbms_scheduler.set_job_argument_value(job_name => 'APPS.JOB_MOSS_DELETE_TEMP_TABLE', argument_position => 1, argument_value => '0'); sys.dbms_scheduler.set_job_argument_value(job_name => 'APPS.JOB_MOSS_DELETE_TEMP_TABLE', argument_position => 2, argument_value => ''); sys.dbms_scheduler.set_job_argument_value(job_name => 'APPS.JOB_MOSS_DELETE_TEMP_TABLE', argument_position => 3, argument_value => ''); sys.dbms_scheduler.enable(name => 'APPS.JOB_MOSS_DELETE_TEMP_TABLE'); end;