oracle 选择天小于今天的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23316922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select rows where day is less than today
提问by ViniciusPires
How do I select rows in the past starting from yesterday in Oracle DB where a field like created_date
is a timestamp(6)
?
如何在 Oracle DB 中从昨天开始选择过去的行,其中字段created_date
是 a timestamp(6)
?
I don't want to compare time, just date.
我不想比较时间,只想比较日期。
采纳答案by ViniciusPires
From the Oracle documentation on SELECT :
SELECT * FROM orders
WHERE created_date < TO_DATE('2014-04-28', 'YYYY-MM-DD');
I can pass this date format from my application, worked like a charm.
我可以从我的应用程序中传递这个日期格式,就像一个魅力。
回答by Gordon Linoff
If you want exactly one day prior to the current time:
如果您想在当前时间前一天:
select *
from table t
where created_date < sysdate - 1;
If you want times before today:
如果你想要今天之前的时间:
select *
from table t
where created_date <= trunc(sysdate);
回答by Saurabh
As you want to compare just date:
由于您只想比较日期:
select *
from table t
where date(created_date) < DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY);
回答by Eng. Samer T
you can use cast function to deal with timestamp as date:
您可以使用 cast 函数将时间戳作为日期处理:
SELECT cast(SYSTIMESTAMP(6) as date)
FROM dual;
so you can select rows with "yesterdate" date by:
因此您可以通过以下方式选择具有“昨天”日期的行:
select ....
where cast(SYSTIMESTAMP(6) as date) like sysdate - 1
note: replace SYSTIMESTAMP(6) with column name which has timestamp type.
注意:将 SYSTIMESTAMP(6) 替换为具有时间戳类型的列名。