时间戳在oracle中有毫秒转换为秒

时间:2014-03-20 10:45:29

标签: sql oracle plsql

我捕获了我需要计算时间的程序的请求和响应时间,通过减去请求 - 响应来查找所花费的时间。

 P_REQUEST_TIME  :='20/MAR/2014 03:03:50.785662 PM';
 P_RESPONSE_TIME :='20/MAR/2014 03:03:50.785816 PM';


 SELECT TO_TIMESTAMP(P_REQUEST_TIME)-TO_TIMESTAMP(P_RESPONSE_TIME) 
 into l_actual_time
 FROM dual;

获得结果是Result:='-000000000 00:00:00.000154000';

我需要这个秒。

3 个答案:

答案 0 :(得分:4)

使用EXTRACT功能。

SELECT EXTRACT(SECOND FROM TO_TIMESTAMP(P_REQUEST_TIME)-TO_TIMESTAMP(P_RESPONSE_TIME)) diff_seconds
FROM <table_name>;

答案 1 :(得分:1)

  select extract( day from diff ) days,
      extract( hour from diff ) hours,
      extract( minute from diff ) minutes,
      extract( second from diff ) seconds
  from (SELECT TO_TIMESTAMP(REQUEST_DTTM)-TO_TIMESTAMP(RESPONS_DTTM) diff FROM hit_tracer);

答案 2 :(得分:0)

如果你想要两个时间戳之间的差异,这是查询

SELECT (P_REQUEST_TIME-P_RESPONSE_TIME) *24 *60*60
     into l_actual_time
     FROM dual;