为什么这个Oracle作业只执行一次?

时间:2013-11-20 15:07:03

标签: oracle plsql jobs

我的Oracle工作定义如下:

BEGIN
  DBMS_SCHEDULER.drop_job('clean_journal_partitions');
  DBMS_SCHEDULER.CREATE_JOB (
    job_name  => 'clean_journal_partitions',
    job_type  => 'STORED_PROCEDURE',
    job_action => 'CLEAN_JOURNAL_PARTITION',
    repeat_interval => 'FREQ=WEEKLY;BYDAY=MON',
    auto_drop => FALSE);
  DBMS_SCHEDULER.ENABLE('clean_journal_partitions');
END;

如果我没错,那应该每周一每周执行一次。问题是它只执行一次,我不知道为什么。

为了能够更轻松地测试它,我修改了它以将频率从每周更改为每10秒,如下所示:

BEGIN
  DBMS_SCHEDULER.drop_job('clean_journal_partitions');
  DBMS_SCHEDULER.CREATE_JOB (
    job_name  => 'clean_journal_partitions',
    job_type  => 'STORED_PROCEDURE',
    job_action => 'CLEAN_JOURNAL_PARTITION',
    repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
    auto_drop => FALSE);
  DBMS_SCHEDULER.ENABLE('clean_journal_partitions');
END;

我也有同样的问题。它只执行一次。任何暗示为什么这个工作不是每10秒执行一次?

1 个答案:

答案 0 :(得分:1)

这在Oracle 11g中对我来说很好用:

CREATE TABLE TEST(
    run_time DATE
); 

CREATE OR REPLACE PROCEDURE CLEAN_JOURNAL_PARTITION AS
BEGIN
    INSERT INTO TEST VALUES(SYSDATE);
    COMMIT;
END;
/

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
    job_name  => 'clean_journal_partitions',
    job_type  => 'STORED_PROCEDURE',
    job_action => 'CLEAN_JOURNAL_PARTITION',
    repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
    auto_drop => FALSE);
  DBMS_SCHEDULER.ENABLE('clean_journal_partitions');
END;

我每10秒在TEST表中输入一个条目。您的问题必须在CLEAN_JOURNAL_PARTITION程序中,可能会崩溃吗?