oracle求时间差的常用函数

时间:2022-10-08 10:23:50
oracle求时间差的常用函数
求时间差: 
天: 
ROUND(TO_NUMBER(END_DATE - START_DATE)) 
小时: 
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24) 
分钟: 
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60) 
秒: 
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60) 
毫秒: 
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60 * 1000)
如果提示无效数字:
将timestamp + 0 后,转换为date,再相减:

select round(to_number(sysdate - (ou_users.start_time+0))) from ou_users
或者用cast 转换:

select round(to_number(sysdate -  cast(ou_users.start_time as date))) from ou_users