Connecting Tech Pros Worldwide Forums | Help | Site Map

check constraint

Newbie
 
Join Date: Feb 2008
Posts: 26
#1: Jul 16 '09
how can i put check constraint for date while creating a table.
I want to pass a constant as a date and do not want to pass as a database variable.

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Jul 16 '09

re: check constraint


Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. create table t12(dat date, CONSTRAINT my_cons CHECK (dat BETWEEN '01-JAN-2009' AND '31-JAN-2009'))
  3.  
  4.  
Newbie
 
Join Date: Jul 2009
Posts: 5
#3: Jul 17 '09

re: check constraint


i have tried that one but not able to create such table.
the following error is being generated


create table t12(dat date,constraint my_cons check(dat between '01-jan-2009' and '31-jan-2009'))
*
ERROR at line 1:
ORA-02436: date or system variable wrongly specified in CHECK constraint
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#4: Jul 17 '09

re: check constraint


Which database version you are using?
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#5: Jul 17 '09

re: check constraint


I am able to create the table using same code as shown:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> create table t12(dat date,constraint my_cons check(dat between '01-jan-2009' and '31-jan-2009')
  3. )
  4.   2  /
  5.  
  6. Table created.
  7.  
  8. SQL> 
  9.  
  10.  
Newbie
 
Join Date: Jul 2009
Posts: 5
#6: Jul 18 '09

re: check constraint


Hi amit

I m using oracle 8i
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#7: Jul 20 '09

re: check constraint


Please post the output of the below query:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * FROM v$version
  3.  
  4.  
Reply