2014-04-08 38 views
0

我想安排一个程序在特定的时间运行,每天三次:在12:00,16:00和18:30。 有什么方法可以创建这样的作业(使用标准的SQL Developer作业向导)?如何在SQL Developer中安排工作

我安排了一项工作,通过设置BYHOUR = 12,16,18和BYMINUTE = 0,30,然后它每天开始六次,这不完全是我想要的。

在此先感谢您的提示!

回答

0

最简单的方法是,如果您不想创建两个作业,则需要创建两个日程表。您可以通过Schedules->新建计划上下文菜单项做到这一点,或者从一个工作表:

begin 
    dbms_scheduler.create_schedule(schedule_name => 'sched_1', 
    repeat_interval => 'FREQ=MINUTELY;BYHOUR=12,16;BYMINUTE=0'); 
    dbms_scheduler.create_schedule('sched_2', 
    repeat_interval => 'FREQ=MINUTELY;BYHOUR=18;BYMINUTE=30'); 
end; 
/

然后在作业向导,设置“重复间隔”来SCHED_1,SCHED_2。当然,你可能需要使用更有意义的名称...

您可以检查时合并计划将运行 - 当前时间之后 - 像这样的东西:

set serveroutput on; 
declare 
    start_date timestamp with time zone; 
    return_date_after timestamp with time zone; 
    next_run_date timestamp with time zone; 
begin 
    start_date := cast(sysdate as timestamp with time zone); 

    for i in 1 .. 8 loop 
    return_date_after := nvl(next_run_date, start_date); 

    dbms_scheduler.evaluate_calendar_string(
     calendar_string => 'sched_1,sched_2', 
     start_date => start_date, 
     return_date_after => return_date_after, 
     next_run_date => next_run_date); 

    dbms_output.put_line('Will run at: ' 
     || to_char(next_run_date, 'YYYY-MM-DD HH24:MI:SS')); 
    end loop; 
end; 
/

Will run at: 2014-04-08 16:00:18 
Will run at: 2014-04-08 18:30:18 
Will run at: 2014-04-09 12:00:18 
Will run at: 2014-04-09 16:00:18 
Will run at: 2014-04-09 18:30:18 
Will run at: 2014-04-10 12:00:18 
Will run at: 2014-04-10 16:00:18 
Will run at: 2014-04-10 18:30:18