1

我如何设置从 06:00 开始并在星期一每小时运行的 dbms_job 的间隔。

X NUMBER:=1102745;    
BEGIN
  SYS.DBMS_JOB.INTERVAL
  (X,
   'next_day(SYSDATE,''MONDAY'')+1/24'
   );
END;

但是这段代码每周一 01:00 有效。

4

1 回答 1

2

您可以使用现代SCHEDULER JOB而不是旧的(和已弃用的)DBMS_JOB

DBMS_SCHEDULER.CREATE_JOB(
       job_name        => 'X'
      ,start_date      => SYSTIMESTAMP
      ,repeat_interval => 'FREQ=HOURLY;BYHOUR=06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23;BYMINUTE=0;BYSECOND=0;BYDAY=Mon'
      ,end_date        => NULL
      ,job_class       => 'DEFAULT_JOB_CLASS'
      ,job_type        => ...
      ,job_action      => ...
    );

您可以使用以下方法验证重复间隔:

DECLARE
    next_run_date TIMESTAMP;
BEGIN
    FOR i IN 1..50 LOOP
        DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING('FREQ=HOURLY;BYHOUR=06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23;BYMINUTE=0;BYSECOND=0;BYDAY=Mon', NULL, next_run_date, next_run_date);
        DBMS_OUTPUT.PUT_LINE ( next_run_date );
    END LOOP;
END;
于 2018-04-18T14:22:45.023 回答