首页 文章

如何在SQL Developer中安排作业

提问于
浏览
0

我想安排一个程序在特定时间运行,一天三次:在12:00,16:00和18:30 . 有没有办法创建这样的工作(使用标准的SQL Developer工作向导)?

我安排了一份工作,设置了BYHOUR = 12,16,18和BYMINUTE = 0,30,但是它每天开始六次,这不是我想要的 .

提前感谢您的提示!

1 回答

  • 1

    如果您不想创建两个作业,最简单的方法是创建两个计划 . 您可以通过Schedules-> New Schedule上下文菜单项或从工作表执行此操作:

    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;
    /
    

    然后在作业向导中,将'Repeat Interval'设置为 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
    

相关问题