473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to check the dob is less than the curent date

i want a create a table with DOB column and i want add a constraint to check the DOB less than the current date using dual table
Apr 27 '14 #1

✓ answered by debasisdas

Try using this.

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE EMP
  2. (EMP_ID   NUMBER(10),
  3.  ENTRY_DATE DATE DEFAULT SYSDATE NOT NULL,
  4.  EMP_DOB  DATE,
  5. CONSTRAINT EMP_DOB_NON_FUTURE CHECK (EMP_DOB <= ENTRY_DATE)
  6. );
Following is the list of Restrictions on Check Constraints in Oracle:

You cannot specify a check constraint for a view. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.

The condition of a check constraint can refer to any column in the table, but it cannot refer to columns of other tables.

Conditions of check constraints cannot contain the following constructs:

Subqueries and scalar subquery expressions

Calls to the functions that are not deterministic (CURRENT_DATE, CURRENT_TIMESTAMP, DBTIMEZONE, LOCALTIMESTAMP, SESSIONTIMEZONE, SYSDATE, SYSTIMESTAMP, UID, USER, and USERENV)

Calls to user-defined functions

Dereferencing of REF columns (for example, using the DEREF function)

Nested table columns or attributes

The pseudocolumns CURRVAL, NEXTVAL, LEVEL, or ROWNUM

Date constants that are not fully specified

2 5244
Luuk
1,047 Expert 1GB
for those who did not know:
the definition of DOB is here

Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER <triggername>
  2. BEFORE INSERT OT UPDATE OF DOB ON <tablename>
  3. FOR EACH ROW
  4. WHEN (new.DOB < CURRENT_DATE)
  5. BEGIN
  6.   raise_application_error( -20001,'DOB must be before today');
  7. END;
  8.  
above answer is not tested.

resources:
1) http://www.toadworld.com/platforms/o...-examples.aspx
2) http://stackoverflow.com/questions/9...d-update-queri
Apr 27 '14 #2
debasisdas
8,127 Expert 4TB
Try using this.

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE EMP
  2. (EMP_ID   NUMBER(10),
  3.  ENTRY_DATE DATE DEFAULT SYSDATE NOT NULL,
  4.  EMP_DOB  DATE,
  5. CONSTRAINT EMP_DOB_NON_FUTURE CHECK (EMP_DOB <= ENTRY_DATE)
  6. );
Following is the list of Restrictions on Check Constraints in Oracle:

You cannot specify a check constraint for a view. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.

The condition of a check constraint can refer to any column in the table, but it cannot refer to columns of other tables.

Conditions of check constraints cannot contain the following constructs:

Subqueries and scalar subquery expressions

Calls to the functions that are not deterministic (CURRENT_DATE, CURRENT_TIMESTAMP, DBTIMEZONE, LOCALTIMESTAMP, SESSIONTIMEZONE, SYSDATE, SYSTIMESTAMP, UID, USER, and USERENV)

Calls to user-defined functions

Dereferencing of REF columns (for example, using the DEREF function)

Nested table columns or attributes

The pseudocolumns CURRVAL, NEXTVAL, LEVEL, or ROWNUM

Date constants that are not fully specified
Apr 28 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: - | last post by:
what is the function to check whether a date, eg 2005-02-44, exists? in php, there is a checkdate() function.
2
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
2
by: Josh Armstrong | last post by:
In a small scheduling DB that I created, I had a list of dates. When the user clicks on a Merge button, I need the system to look at the list and see if a date exists if it does give a message. ...
2
by: DaveF | last post by:
I am using the following code to see if the image is there, is there a way to check the image date as well? Dim sTxt As String If strURL <> "" Then If Left(LCase(strURL), 7) <> "http://" Then...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
9
by: User | last post by:
Hi, Assuming the date format is in 31-Feb-2006 <head> <script language="javascript"> function t() { mill=new Date(2006, 01, 31) ;
1
by: Iain | last post by:
Hi All I've 2 calendar controls on my web form - i need to check if Calender1 date selected is greater than Calender 2 date selected (and then display an error message) TIA iain
2
by: Andrew Poulos | last post by:
If I check for a invalid date e.g. February 30th, 2008? Andrew Poulos
2
by: KMEscherich | last post by:
Microsoft Access 2003 Hi there, am stuck with something that I am not sure on how to get done. I am attempting to have 3 check boxes and have 3 date fields. I need to have each date field be...
3
by: tutusaint | last post by:
I have a registration page which captures details including birth date and registration date. The birth date and Date is not captured in mysql database. Please help Registration.php <?php if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.