在Oracle中,如何从日期减法中删除“加号”?

时间:2015-05-06 17:43:13

标签: sql oracle oracle11g

我有以下代码:

NUMTODSINTERVAL((hur.end_date -hur.creation_date), 'day') 
                               AS "Average Security Appr Duration" 

问题在于它返回的内容如下:

+1115 11:47:23.0000000

如何将其格式设置为用户友好,特别是删除+符号?

"1,115 DAYS, 11 HOURS 47 minutes"

2 个答案:

答案 0 :(得分:2)

使用EXTRACTTO_CHAR

SELECT TO_CHAR(EXTRACT(DAY    FROM t_interval), 'fm99999') || ' DAYS '    ||
       TO_CHAR(EXTRACT(HOUR   FROM t_interval), 'fm99')    || ' HOURS '   ||
       TO_CHAR(EXTRACT(MINUTE FROM t_interval), 'fm99')    || ' MINUTES ' ||
       TO_CHAR(EXTRACT(SECOND FROM t_interval), 'fm99.0')  || ' SECONDS' 
                                                 AS "Average Security Appr Duration" 
  FROM (SELECT NUMTODSINTERVAL((hur.end_date -hur.creation_date), 'day') AS t_interval 
          FROM dual);

这会产生类似1 DAYS 18 HOURS 18 MINUTES 3.0 SECONDS的输出。

答案 1 :(得分:1)

使用提取函数处理间隔,例如

extract(day from myinterval)

将返还您的天数。