2016-12-27 5 views
1

私は2つの数値列start_timeとseen_timeを持つテーブルを持っています。開始時間を意味2つの時間列を変換して減算する

Start_time   Seen_time 
1345    1520 

13:45とseen_time 3:20 PM

私は列を減算し、楽しみのためだけに1:35時間

+0

DATEDIFF()関数を試しましたか? –

+0

構文を書いてください。 –

+0

表の定義と列のデータ型、完全で正確なサンプルデータを表示してください。オラクルには「時間」のようなものはありません。タイプコンポーネントが含まれているDATE型があるため、あなたの質問は不明です。 – OldProgrammer

答えて

0

もなりたい...ではありません私は真剣に何かをコード化する方法です(ただし実際には、問題を正しく効率的に解決します)。このコードは、OPのデータモデルと同じように珍しいものです(重要なことは何もしないでください)。

with 
    inputs (time_from, time_to) as (
     select 32, 233 from dual union all 
     select 1030, 2322 from dual union all 
     select 2200, 1130 from dual union all 
     select 2030, 3544 from dual union all 
     select 1233, 2051 from dual union all 
     select 1215, 1360 from dual 
    ) 
-- end of test data; solution (SQL query) begins below this line 
select time_from, time_to, 
     case when time_from > time_to then 'Error: time_from > time_to' 
      when trunc(time_from/100) > 23 then 'Error: invalid hours in time_from' 
      when mod (time_from , 100) > 59 then 'Error: invalid minutes in time_from' 
      when trunc(time_to /100) > 23 then 'Error: invalid hours in time_to' 
      when mod (time_to , 100) > 59 then 'Error: invalid minutes in time_to' 
      else to_char(time_to - time_from - 
        case when mod(time_to, 100) < mod(time_from, 100) then 40 else 0 end, 
        'FM00G00L', 'nls_numeric_characters='',:'' nls_currency='' h''') 
      end as time_diff 
from inputs 
; 

TIME_FROM TIME_TO TIME_DIFF 
---------- -------- ----------------------------------- 
     32  233 02:01 h 
     1030  2322 12:52 h 
     2200  1130 Error: time_from > time_to 
     2030  3544 Error: invalid hours in time_to 
     1233  2051 08:18 h 
     1215  1360 Error: invalid minutes in time_to 

6 rows selected. 
関連する問題