0

这是让我在 TEXT FORMAT 中输出 HH:MM:SS的查询。我想要时间格式的输出,以便可以对其进行操作、排序和搜索。

我可以把它作为一个数字吗?

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
4

1 回答 1

2

我不遵循您对值进行的操作(天* 10 和小时可能为-14),但原则上,一旦您拥有单独的组件,而不是将它们与您连接起来,:您可以将它们加在一起,每个一除以适当的值以转换为一天的分数(因此该hour值除以 24,minute除以 24*60 等)。

随机选择一个间隔值(并且没有您的调整):

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                                         
于 2013-07-03T12:25:31.160 回答