簡體   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