问题
What would be the expression to check if someone's 20 years or over without hard-coding the date?
In the SQL
SELECT student_fname
FROM students
WHERE dob<'05-MAR-1995';
I was thinking about using SYSDATE but then I don't know the syntax to subtract 20 years.
回答1:
WHERE dob < add_months( trunc(sysdate), -12*20 );
would work assuming that you want to ignore the time component of sysdate.
来源:https://stackoverflow.com/questions/28888848/how-to-subtract-years-from-sysdate