繁体   English   中英

oracle 开发人员中的 SQL 日期比较

[英]SQL date comparision in oracle developer

我有一个带有日期列的表。 但是当我使用 '>' 运算符时,返回的结果集与预期不符。

select * from table where birth_day > '10-jan-2020';

预期结果集不应具有 2020 年 1 月 10 日的值,因为使用了查询“>”。 但在结果集中,我看到的是 10-jan-2020,11-jan-2020... sql 的行为方式是这样的吗?

尝试这个:

select * from table where birth_day >= to_date('2020.01.11', 'yyyy.mm.dd');

在 oracle 中, Date数据类型也存储时间。

所以你有多种选择来获取结果,如下所示:

select * from table where birth_day >= date '2020-01-10' + 1; 
-- all the birth_day having date >= 2020-01-10 00:00:00 will be included

select * from table where trunc(birth_day) > date '2020-01-10';  
-- trunc(birth_day) will trunc the date to starting of the day - 00:00:00 
-- so it will work without adding one day to your date '2020-01-10'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM