你可以得到毫秒這樣的:如果
[email protected]_SCOTTY1-VM> select to_char(SYSTIMESTAMP, 'hh24:mi:ss:ff3') from dual;
TO_CHAR(SYSTIMESTAMP,'HH24:MI:SS:FF3')
------------------------------------------------------
16:06:10:944
[email protected]_SCOTTY1-VM> select to_char(SYSTIMESTAMP, 'hh24:mi:ss:ff3') from dual;
TO_CHAR(SYSTIMESTAMP,'HH24:MI:SS:FF3')
------------------------------------------------------
16:06:12:241
[email protected]_SCOTTY1-VM>
你需要的數字表示INTERVAL對象可以使用這些函數:
/*
** **************************************************************************
*/
Function daysBetween
(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)
+ extract(hour from i)/60
+ extract(minute from i)/60/60
+ extract(second from i)/60/60/60
, numDec);
End;
/*
** **************************************************************************
*/
Function hoursBetween
(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
+ extract(hour from i)
+ extract(minute from i)/60
+ extract(second from i)/60/60
, numDec);
End;
/*
** **************************************************************************
*/
Function minutesBetween
(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
+ extract(hour from i)*60
+ extract(minute from i)
+ extract(second from i)/60
, numDec);
End;
/*
** **************************************************************************
*/
Function secondsBetween
(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
+ extract(hour from i)*60*60
+ extract(minute from i)*60
+ extract(second from i)
, numDec);
End;
/*
** **************************************************************************
*/
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;
它被稱爲v $ session_longops,因爲它的目的是監視長操作:-)您可以在操作前後捕獲systimestamp並計算差異,並且應該使您的精度達到6位小數。 – 2011-04-29 20:49:55
@Martin Schapendonk:是的,那就是我最終做的。對於大型數據集(更接近「真正」大小的數據集),這些操作*需要足夠長的時間才能正常註冊。它適用於非常小的特定測試,它們運行速度太快,不易監控。 – FrustratedWithFormsDesigner 2011-04-29 21:05:55