Connor and Chris will both be at AI World from October 12 to October 17 , the premier Oracle conference of 2025. If you're in Vegas, please come say Hi or pop into our sessions
Thanks for the question, Navya.
Asked: August 20, 2018 - 6:35 pm UTC
Last updated: August 22, 2018 - 2:20 am UTC
Version: Oracle 12.12
Viewed 1000+ times
(select(CASE WHEN Tab1 .DEPARTURE_TIMESTAMP IS NOT NULL AND Tab1.ARRIVAL_TIMESTAMP IS NOT NULL AND Tab1.ARRIVAL_TIMESTAMP < Tab1.DEPARTURE_TIMESTAMP THEN to_char(lpad(trunc(24*mod(Tab1.DEPARTURE_TIMESTAMP - Tab1.ARRIVAL_TIMESTAMP,1)), 2,0)) || ':' || to_char(lpad(trunc(mod(mod(Tab1.DEPARTURE_TIMESTAMP - Tab1.ARRIVAL_TIMESTAMP,1)*24,1)*60),2,0)) ||':' || to_char(lpad(trunc(mod(mod(mod(Tab1.DEPARTURE_TIMESTAMP -Tab1.ARRIVAL_TIMESTAMP,1)*24,1)*60,1)*60),2,0)) ELSE '' END) from ( select * from TABLE1 where txn_id=SJ.SERVICE_JOB_ID order by last_modified_date desc )Tab1 where rownum=1)as DURATION
SQL> create table t ( df date, dt date ); Table created. SQL> SQL> insert into t values ( sysdate, sysdate + 0.2 ); 1 row created. SQL> insert into t values ( sysdate, sysdate + 2.2 ); 1 row created. SQL> SQL> select 2 to_char(lpad(trunc(trunc(dt-df)*24+24*mod(dt - df,1)), 2,0)) || ':' || 3 to_char(lpad(trunc(mod(mod(dt - df,1)*24,1)*60),2,0)) ||':' || 4 to_char(lpad(trunc(mod(mod(mod(dt - df,1)*24,1)*60,1)*60),2,0)) 5 from t; TO_CHAR(LPAD(TRUNC(TRUNC(D -------------------------- 04:48:00 52:48:00
Check out more PL/SQL tutorials on our LiveSQL tool.
PL/SQL reference manual from the Oracle documentation library