用于查找超过 30 天的日期记录的 Oracle SQL Where 子句

编程入门 行业动态 更新时间:2024-10-10 12:20:02
本文介绍了用于查找超过 30 天的日期记录的 Oracle SQL Where 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用创建日期字段在(Oracle SQL)表中查找记录超过 30 天的记录.使用像 > 这样的运算符查找记录会很好,但是如果有人可以建议使用快速 SQL where 子句语句来查找超过 30 天的记录,那就太好了.请建议我使用的 Oracle 语法.

I want to find records in a (Oracle SQL) table using the creation date field where records are older than 30 days. It would be nice to find records using a operators like > but if anyone can suggest quick SQL where clause statement to find records older than 30 days that would be nice. Please suggest Oracle syntax as that is what I am using.

推荐答案

使用:

SELECT * FROM YOUR_TABLE WHERE creation_date <= TRUNC(SYSDATE) - 30

SYSDATE 返回日期 &时间;TRUNC 将日期重置为午夜,因此如果您想要 creation_date 即 30 天前,包括当前时间.

SYSDATE returns the date & time; TRUNC resets the date to being as of midnight so you can omit it if you want the creation_date that is 30 days previous including the current time.

根据您的需要,您还可以考虑使用 ADD_MONTHS:

Depending on your needs, you could also look at using ADD_MONTHS:

SELECT * FROM YOUR_TABLE WHERE creation_date <= ADD_MONTHS(TRUNC(SYSDATE), -1)

更多推荐

用于查找超过 30 天的日期记录的 Oracle SQL Where 子句

本文发布于:2023-10-17 09:33:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500476.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子句   日期   SQL   Oracle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!