偶然用oralce 中的两个时间的比较 发现 用到的oralce 中的函数 to_date() 不好使 得到的信息是错误的才发现如果在oralce 数据库中对于时间比较得到的值是 天 明白了这个就好办了 将时间转换成你想要的对象 如: 如果你想比较得到秒的值:--两个时间直接相减得到的是相差的天数 (to_date(t.time,'yyyy-mm-dd hh24:mi:ss')- to_date(fro.time,'yyyy-mm-dd hh24:mi:ss'))*24*60*60>3 --例如: select (sysdate-to_date('20101111','yyyymmdd'))*24*60*60 from dual (SYSDATE-TO_DATE('20101111','YYYYMMDD'))*24*60*60 ------------------------------------------------- 221335
对 这是一个解决思想
如果你使用的是oracle 10g以上的 用一个函数就可以了 interval '3' second 这就是表示的3秒
查询句子就是:
select * from table1 as t,table2 as fro where 1=1and (to_date(t.time,'yyyy-mm-dd hh24:mi:ss') - interval '3' second >to_date(fro.time,'yyyy-mm-dd hh24:mi:ss'));
问题就这样解决了!
本文介绍了在Oracle数据库中进行时间比较的有效方法。通过使用to_date()函数将时间转换为天数,再乘以24*60*60来获取秒级别的差值。此外,对于Oracle 10g及以上版本,可以利用interval函数简化时间间隔的计算。
3327

被折叠的 条评论
为什么被折叠?



