oracle中两个字段相减取时间值问题

a字段20130620101647,b字段20130620094008,a字段减b字段取值为时间秒,怎么做呢?谢谢!

select (to_date('20130620101647','yyyymmddhh24miss')-to_date('20130620094008','yyyymmddhh24miss'))*86400 from dual;


前边是两个时间相减,得到天数,然后天数*每天的秒数(每天86400秒),结果就是你要的秒

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-06-24
 select to_Date('20130620101647', 'yyyymmddhh24miss') , to_Date('20130620094008', 'yyyymmddhh24miss'),
             round((to_Date('20130620101647', 'yyyymmddhh24miss') - to_Date('20130620094008', 'yyyymmddhh24miss')) * 60*60 * 24, 0)
  from dual;

第2个回答  2013-06-24
用to_date 转成date格式 再减