SQL 如何从系统日期中减去年份

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

How to subtract years from sysdate

sqloracle

提问by redCodeAlert

What would be the expression to check if someone's 20 years or over without hard-coding the date?

在没有硬编码日期的情况下检查某人是否 20 岁或以上的表达式是什么?

In the SQL

在 SQL

 SELECT student_fname 
 FROM students
 WHERE dob<'05-MAR-1995';

I was thinking about using SYSDATEbut then I don't know the syntax to subtract 20 years.

我正在考虑使用,SYSDATE但后来我不知道减去 20 年的语法。

回答by Justin Cave

WHERE dob < add_months( trunc(sysdate), -12*20 );

would work assuming that you want to ignore the time component of sysdate.

假设您想忽略sysdate.