oracle时间范围查询

当时间精确到秒的指标和时间精确到日的时间进行对比是恒不等于的,但是可以判断大于或者等于的情况。

举个例子,指标【时间精确到秒】

select 时间精确到秒 
from table
where 时间精确到秒<= to_date('2013-11-20 ', 'yyyy-MM-dd ')
and 时间精确到秒 >= to_date('2013-11-20 ', 'yyyy-MM-dd ')

明显数据查询2013-11-20那天没有数据,而如果sql如下写发现数据库中是存在数据的。

select 时间精确到秒 
from table
where to_date(to_char(时间精确到秒,'yyyy-MM-dd'),'yyyy-MM-dd') <= to_date('2013-11-21 ', 'yyyy-MM-dd ')
and to_date(to_char(时间精确到秒,'yyyy-MM-dd'),'yyyy-MM-dd') >= to_date('2013-11-20 ', 'yyyy-MM-dd ')

因此,我们可以得出结论:

当【时间指标精确到秒】与【时间精确到日】的对比进行范围查询时不能查询当天的数据,因此必须对【时间指标精确到秒】进行格式转换成到日的时间格式。

posted @ 2013-11-21 16:25  爱笑的狐狸  阅读(1707)  评论(0编辑  收藏  举报