我有一个创建 n 个工作的 Oracle For 循环。对于创建的每个作业,开始日期与上一个作业相隔 10 秒。但由于某种原因,每个作业都会在 1 秒内启动。未来的工作在 Oracle 中是不可能的吗?
LTIMESTAMP := SYSTIMESTAMP;
FOR REC IN (SELECT *
FROM ORDERS
WHERE PROCESS_FLAG = CST_IS_ELIGIBLE_FOR_PROCESSING
ORDER BY ORDER_DATE ASC)
LOOP
LJOBNAME := CST_JOB_NAME_PREFIX || TO_CHAR(REC.ORDER_ID);
DBMS_SCHEDULER.CREATE_PROGRAM(PROGRAM_NAME => CST_PROGRAM_NAME,
PROGRAM_ACTION => 'PKG_BATCH_MAIN.SP_START_JOB',
PROGRAM_TYPE => 'STORED_PROCEDURE',
NUMBER_OF_ARGUMENTS => 2,
ENABLED => FALSE);
DBMS_SCHEDULER.DEFINE_PROGRAM_ARGUMENT(PROGRAM_NAME => CST_PROGRAM_NAME,
ARGUMENT_POSITION => 1,
ARGUMENT_TYPE => 'NUMBER');
DBMS_SCHEDULER.DEFINE_PROGRAM_ARGUMENT(PROGRAM_NAME => CST_PROGRAM_NAME,
ARGUMENT_POSITION => 2,
ARGUMENT_TYPE => 'NUMBER');
DBMS_SCHEDULER.ENABLE(CST_PROGRAM_NAME);
DBMS_SCHEDULER.CREATE_JOB(JOB_NAME => LJOBNAME,
PROGRAM_NAME => CST_PROGRAM_NAME,
START_DATE => LTIMESTAMP,
REPEAT_INTERVAL => 'FREQ=SECONDLY; BYSECOND=1',
END_DATE => NULL,
AUTO_DROP => TRUE,
ENABLED => FALSE,
COMMENTS => 'Job launched for each ORDER detail id');
DBMS_SCHEDULER.SET_ATTRIBUTE(LJOBNAME,
'MAX_RUNS',
1);
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE(LJOBNAME,
1,
TO_CHAR(REC.ORDER_ID));
DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE(LJOBNAME,
2,
TO_CHAR(REC.ORDER_DETAILS_ID));
DBMS_SCHEDULER.ENABLE(LJOBNAME);
LTIMESTAMP := LTIMESTAMP + INTERVAL '10' SECOND;
END LOOP;