Skip to content
Advertisement

How can i check that a user is 12 and over sql

How do I check that when a user enters their date of birth into my database that they are 12 and over?

I am using SQL plus.

Right now I have somthing like this:

The problem with this is that it does not update every day, so the ‘2002-02-09’ should be changed every day.

I know what to do but I’m not sure how to execute it. I want to get the ‘Dateofbirth’ & sysdate – 12 years and if user is above 12 it will let them.

Advertisement

Answer

Oracle won’t you let use sysdate in a check constraint (or other functions whose return value is not constant over time).

You can, however, write a trigger that implements the same logic:

Demo on DB Fiddle:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement