如何使用Oracle dbms_scheduler每5分钟运行一次程序,每天从上午7:30到下午21:30?

时间:2019-02-20 10:24:42

标签: database oracle scheduler

我正在使用oracle 12c DB。我必须安排一个程序,每天从上午7:30到下午21:30每5分钟运行一次。 该程序实际上每天从08:00运行到20:55

begin
dbms_scheduler.create_job(
job_name=>'JobInvioSmsVa',
job_type=>'plsql_block',
repeat_interval=> 'FREQ=DAILY;BYHOUR=8,9,10,11,12,13,14,15,16,17,18,19,20;BYMINUTE=0,5,10,15,20,25,30,35,40,45,50,55',
job_action=>'INVIO_SMS_VA;',
enabled=>true);
end;
/

2 个答案:

答案 0 :(得分:0)

您可以简单地:

  begin
    dbms_scheduler.create_job(
    job_name=>'JobInvioSmsVa',
    job_type=>'plsql_block',
    repeat_interval=> 'FREQ=DAILY;BYHOUR=7,8,9,10,11,12,13,14,15,16,17,18,19,20,21;BYMINUTE=0,5,10,15,20,25,30,35,40,45,50,55',
    job_action=>
     'begin
       if sysdate 
         between trunc(sysdate)+7.5/24 
         and trunc(sysdate)+21.5/24 
       then
         INVIO_SMS_VA;
       end if;  
     end;',
    enabled=>true);
    end;
    /

答案 1 :(得分:0)

您可以创建三个时间表:

begin

dbms_scheduler.create_job(
   job_name=>'JobInvioSmsVa',
   job_type=>'plsql_block',
   repeat_interval=> 'FREQ=DAILY;BYHOUR=8,9,10,11,12,13,14,15,16,17,18,19,20;BYMINUTE=0,5,10,15,20,25,30,35,40,45,50,55',
   job_action=>'INVIO_SMS_VA;',
   enabled=>true);

dbms_scheduler.create_job(
   job_name=>'JobInvioSmsVa_morning',
   job_type=>'plsql_block',
   repeat_interval=> 'FREQ=DAILY;BYHOUR=7;BYMINUTE=30,35,40,45,50,55',
   job_action=>'INVIO_SMS_VA;',
   enabled=>true);

dbms_scheduler.create_job(
   job_name=>'JobInvioSmsVa_evening',
   job_type=>'plsql_block',
   repeat_interval=> 'FREQ=DAILY;BYHOUR=21;BYMINUTE=0,5,10,15,20,25,30',
   job_action=>'INVIO_SMS_VA;',
   enabled=>true);

end;

/

INCLUDE子句不能与BYHOURBYMINUTE组合使用,因此不能将它们组合成一个时间表。