[英]EXTRACT Hour Function is not working as expected
I have a select query where i take difference between two timestamps 我有一个选择查询,我在两个时间戳之间求差
select EXTRACT (HOUR FROM (systimestamp-queuereceiveddate(a,b)))
from dual
The queuereceived
date function also returns a timestamp. queuereceived
日期函数还返回时间戳。 I am able to extract days by using the extract function but not hours. 我可以使用提取功能来提取天数,而不能提取几个小时。
Please advise on this 请对此提供意见
Extracting the hour certainly works: 提取小时当然可以:
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
If you're expecting it to show the total number of hours, if the difference is more than one day, then you misunderstand what the extract function is doing, and you'll need to calculate a total by multiplying the day
value by 24 and adding that to the hour
value: 如果您期望它显示总小时数,如果相差超过一天,那么您会误解提取函数的作用 ,并且您需要将
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
Of course I'm guessing since you haven't explained the problem you're seeing, but since the function does work this is the only thing I can think you mean... 我想当然是在猜测,因为您还没有解释所遇到的问题,但是由于函数确实起作用,所以这是我能想到的唯一一件事...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.