我有一个选择查询,我在其中获取两个时间戳之间的差异
select EXTRACT (HOUR FROM (systimestamp-queuereceiveddate(a,b)))
from dual
queuereceived
date 函数还返回一个时间戳。我可以使用提取功能提取天数,但不能提取小时数。
请就此提出建议
提取小时肯定有效:
select systimestamp - (systimestamp - 27.5/24) as diff,
extract(day from systimestamp - (systimestamp - 27.5/24)) as diff_day,
extract(hour from systimestamp - (systimestamp - 27.5/24)) as diff_hour
from dual;
DIFF DIFF_DAY DIFF_HOUR
------------------------------ ---------- ----------
+000000001 03:30:00.584929 1 3
如果您希望它显示总小时数,如果差异超过一天,那么您误解了extract 函数在做什么,您需要通过将day
值乘以 24 并添加来计算总数那个hour
值:
select systimestamp - (systimestamp - 27.5/24) as diff,
extract(day from systimestamp - (systimestamp - 27.5/24)) * 24
+ extract(hour from systimestamp - (systimestamp - 27.5/24))
as diff_hour_total
from dual;
DIFF DIFF_HOUR_TOTAL
------------------------------ ---------------
+000000001 03:30:00.612830 27
当然我猜是因为你没有解释你看到的问题,但是因为这个功能确实有效,这是我唯一能认为你的意思......