这是我的输出为 HH:MM:SS in TEXT FORMAT 的查询。我想要时间格式的输出,以便可以对其进行操作,排序和搜索。
我能把它作为一个数字吗?
EXTRACT (DAY FROM interval)*10 + EXTRACT (HOUR FROM interval) -
CASE
WHEN EXTRACT(HOUR FROM CAST(date2 AS TIMESTAMP)) > EXTRACT(HOUR FROM CAST(date 1 AS TIMESTAMP))
THEN
14
ELSE
0
END || ':' || EXTRACT (MINUTE FROM interval) || ':' ||
EXTRACT (SECOND FROM interval) CB_END_TV_START
答案 0 :(得分:2)
我不遵循你对你的价值所做的操纵(当天* 10和小时可能是-14),但是一旦你拥有单独的组件,而不是用:
连接它们。你可以把它们加在一起,每一个都用适当的值除以转换成一天的分数(所以hour
值除以24,minute
乘以24 * 60等。) / p>
随机选择间隔值(无需调整):
with t42 as ( select numtodsinterval(147.147, 'HOUR') as interval from dual)
select interval,
extract (day from interval)
+ (extract (hour from interval) / 24)
+ (extract (minute from interval) / (24*60))
+ (extract (second from interval) / (24*60*60)) as num
from t42;
INTERVAL NUM
----------- ----------
6 3:8:49.2 6.131125
NUM
值代表部分天数;您可以将其转换回以下区间:
select numtodsinterval(6.131125, 'DAY') from dual;
NUMTODSINTERVAL(6.131125,'DAY')
-------------------------------
6 3:8:49.2
或者像这样的字符串,将其添加到已知的固定日期:
select to_char(date '1900-01-01' + 6.131125 - 1, 'D HH24:MI:SS') from dual;
TO_CHAR(DATE'1900-01-01'+6.131125-1,'DHH24:MI:SS')
--------------------------------------------------
6 03:08:49