我必须找到这两个时间戳之间的区别,请帮助我
27-FEB-12 02.11.31.910000000 AM, 27-FEB-12 02.11.49.002000000 AM
答案 0 :(得分:2)
减去它们。结果将是INTERVAL
数据类型,在本例中为17.092秒。
SQL> ed
Wrote file afiedt.buf
1 select to_timestamp( '27-FEB-12 02.11.31.910000000 AM', 'DD-MON-RR HH.MI.SS.FF9 AM') -
2 to_timestamp( '27-FEB-12 02.11.49.002000000 AM', 'DD-MON-RR HH.MI.SS.FF9 AM')
3* from dual
SQL> /
TO_TIMESTAMP('27-FEB-1202.11.31.910000000AM','DD-MON-RRHH.MI.SS.FF9AM')-TO_
---------------------------------------------------------------------------
-000000000 00:00:17.092000000
答案 1 :(得分:1)
要更好地控制输出的显示方式,可以使用EXTRACT
:
SQL> SELECT TO_CHAR(EXTRACT(HOUR FROM (x.ts2 - x.ts1)) ,'fm00') hours
2 , TO_CHAR(EXTRACT(MINUTE FROM (x.ts2 - x.ts1)) ,'fm00') minutes
3 , TO_CHAR(EXTRACT(SECOND FROM (x.ts2 - x.ts1)) ,'fm00.' || RPAD('0',9,'0')) seconds
4 FROM (SELECT TO_TIMESTAMP('27-FEB-12 02.11.31.910000000 AM', 'DD-MON-RR HH.MI.SS.FF9 AM') ts1
5 , TO_TIMESTAMP('27-FEB-12 02.11.49.002000000 AM', 'DD-MON-RR HH.MI.SS.FF9 AM') ts2
6 FROM DUAL) x
7 ;
HOU MIN SECONDS
--- --- -------------
00 00 17.092000000
SQL>
请参阅http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions052.htm。