2

私は次のSQLクエリを持っています:

    SELECT 
    TO_CHAR(Event1, 'HH24:MI:SS'),
    TO_CHAR(Event2, 'HH24:MI:SS'),
    TO_CHAR((Event1-Event2) * -1440) AS Elapsed
...

これにより、event1とevent2が発生した2時間の経過時間が分単位でわかります。

私の質問:経過時間を分単位ではなく次の形式で表示するにはどうすればよいですHH24:MI:SSか?

4

2 に答える 2

1

試す

select 
TRUNC(event1-event2)||':'||
TRUNC(MOD(event1-event2),1)*24)||':'||
TRUNC(MOD(MOD(event1-event2),1)*24,1)*60)||':'||
TRUNC(MOD(MOD(MOD((event1-event2),1)*24,1)*60,1)*60) as elapsed
于 2012-11-09T21:33:01.323 に答える
1

TIMESTAMPに変換すると、間隔データ型になります。

SQL> create table test(a date, b date);

Table created.

SQL> insert into test values (sysdate - 1.029384, sysdate);

1 row created.

SQL> select 1440*(b-a) diff_in_secs from test;

DIFF_IN_SECS
------------
  1482.31667

SQL> select (cast(b as timestamp)-cast(a as timestamp)) diff_in_secs from test;

DIFF_IN_SECS
---------------------------------------------------------------------------
+000000001 00:42:19.000000

extract('hour' from your_interval_expression)などで個々の要素を抽出できます。

SQL> select extract(day from diff)||'d '||extract(hour from diff)||'h '||extract(minute from diff)||'m '||extract(second from diff)||'s' from (select (cast(b as timestamp)-cast
(a as timestamp)) diff from test);

EXTRACT(DAYFROMDIFF)||'D'||EX
--------------------------------------------------------------------------------
1d 0h 42m 19s
于 2012-11-09T15:30:21.363 に答える