2015-05-06 55 views
0

我有以下代碼:在Oracle中,如何從日期減法中刪除「加號」?

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

使用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

使用提取功能與間隔工作,e.g

extract(day from myinterval) 

將返回天量。