2011-11-17 62 views

回答

1

考慮的情況下,你需要兩個時間戳之間的毫秒數如下:

create or replace Function msecBetween 
    (ts1 timestamp with time zone, 
    ts2 timestamp with time zone, 
    numDec number default 0 
    ) 
    Return Number is 
    i INTERVAL DAY(3) TO SECOND(3) := ts2 - ts1; 
    Begin 
    return round (
     +  extract(day from i)*24*60*60*1000 
     +  extract(hour from i)*60*60*1000 
     +  extract(minute from i)*60*1000 
     +  extract(second from i)*1000 
    , numDec); 
    End; 
+0

嗨,對不起,這個麻煩。我不太明白這個功能是如何工作的。但是當我在我的oracle sql開發人員程序上執行它時,它給了我錯誤的ORA-00928:缺少SELECT關鍵字 00928. 00000 - 「missing SELECT keyword」 *原因: *操作: Line error:29 Column:1 – JLearner

+0

嗨,對不起 - 我在函數前面忘了「創建或替換」...注意,要在SQL * Plus中創建函數,您需要在最後一行輸入/後面。 –

4

只是減去他們:

SQL> select (systimestamp + 1) - systimestamp from dual; 

(SYSTIMESTAMP+1)-SYSTIMESTAMP 
--------------------------------------------------------------------------- 
+000000000 23:59:59.884789 
+0

嗨感謝您有用的戳! – JLearner

相關問題