Oracle 查询从最近 10 分钟插入的表中获取数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/890035/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:52:29  来源:igfitidea点击:

Oracle query to get Data from table inserted in last 10 mins

oracledatetime

提问by RBS

I have to get data from Oracle Table in which I have one datefield called lastupdatedDateand I want to get only that rows back in which lastupdatedDateis in last 10 mins of sysdate

我必须从 Oracle 表中获取数据,其中我调用了一个日期字段lastupdatedDate,我只想返回lastupdatedDate过去 10 分钟内的那些行sysdate

For example, if in my table I have lastupdateDateas 05/20/09 4:20:44then I want this row back in my result if I run the query in between 05/20/09 4:20:44and 05/20/09 4:30:44, and not if if I run the query at 05/20/09 5:31:44.

例如,如果在我的表中有lastupdateDateas 05/20/09 4:20:44那么如果我在05/20/09 4:20:44和之间运行查询,我希望这一行回到我的结果中05/20/09 4:30:44,而不是如果我在05/20/09 5:31:44.

采纳答案by RedFilter

select *
from mytable
where lastupdatedDate > sysdate - (10/1440)

A more readable version of this is given by Rob van Wijk here https://stackoverflow.com/a/893668/39430

Rob van Wijk 在此处提供了更具可读性的版本https://stackoverflow.com/a/893668/39430

回答by Rob van Wijk

Or slightly more readable:

或者稍微更具可读性:

select *
  from mytable
 where lastupdatedDate > sysdate - interval '10' minute

回答by curtisk

select sysdate - 10/(24*60) from dual;

See above example to get sysdate minus ten minutes, now just add to your query

请参阅上面的示例以将 sysdate 减去十分钟,现在只需添加到您的查询中