2017-05-11 50 views
1

我有一個Oracle For循環,它創建n個作業。 對於創建的每個作業,開始日期與以前的作業間隔爲10秒。 但由於某種原因,每項工作都在1秒內發起。 Oracle在未來的工作是不可能的嗎?Oracle Job根據開始日期參數不起始

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; 
+0

你能告訴我們你寫的代碼嗎? – Nitish

+0

對於其中一些工作,您可以給我們'DBA_SCHEDULER_JOB_RUN_DETAILS'的LOG_DATE,REQ_START_DATE,ACTUAL_START_DATE,RUN_DURATION嗎? – JSapkota

回答

0

我猜LTIMESTAMP是timestamp數據類型insted的的TIMESTAMP WITH TIME ZONE。在自動轉換過程中,您會失去時間戳的準確性。

調度程序使用的時區SELECT * FROM dba_scheduler_global_attribute WHERE attribute_name = 'DEFAULT_TIMEZONE';

在會話你正在使用的時區SELECT sessiontimezone FROM DUAL;

declare 
with_timestamp TIMESTAMP WITH TIME ZONE := systimestamp; 
no_timestamp timestamp     := with_timestamp; 
auto_conversion TIMESTAMP WITH TIME ZONE := no_timestamp; 
begin 
dbms_output.put_line(to_char(with_timestamp,'YYYY-MM-DD hh24:mi:ss TZR')); 
dbms_output.put_line(to_char(no_timestamp,'YYYY-MM-DD hh24:mi:ss TZR')); 
dbms_output.put_line(to_char(auto_conversion,'YYYY-MM-DD hh24:mi:ss TZR')); 

end; 

從我的服務器結果

2017-05-11 09:15:44 +01:00 
2017-05-11 09:15:44 +00:00 
2017-05-11 09:15:44 +02:00 

在我的情況下,所有JOBY將在一小時內開始。您的start_date早於調度程序的當前日期。

+0

嘗試將時間戳記中的LTIMESTAMP數據類型更改爲TIMESTAMP WITH TIME ZONE,但仍然存在相同問題 –

相關問題