场景应用:
两个时间相差多少?时?分?秒?
字段A varchar2 类型 2018-02-26 07:05:00
在oracle 中,时间加减运算后的结果是以天为单位的,如果想得到秒,则乘以 86400(一天的秒数 24*60*60) 就好了
想得到分 24*60
--天
select (to_date( t.A,'yyyy-mm-dd hh24:mi:ss')- to_date( t.B,'yyyy-mm-dd hh24:mi:ss')) from table t
--小时
select (to_date( t.A,'yyyy-mm-dd hh24:mi:ss')- to_date( t.B,'yyyy-mm-dd hh24:mi:ss'))*24 from table t
--分
select (to_date( t.A,'yyyy-mm-dd hh24:mi:ss')- to_date( t.B,'yyyy-mm-dd hh24:mi:ss'))*24*60 from table t
--秒
select (to_date( t.A,'yyyy-mm-dd hh24:mi:ss')- to_date( t.B,'yyyy-mm-dd hh24:mi:ss'))*24*60*60 from table t