Re: CHECK Constraint

From: Stephen_CA <steveee_ca_at_yahoo.com>
Date: 8 Sep 2003 08:04:55 -0700
Message-ID: <3485967d.0309080629.54d6d6fb_at_posting.google.com>


hari_om_at_hotmail.com (Hari Om) wrote in message news:<d1d5ebe4.0309051319.33b3c3b2_at_posting.google.com>...
> Hi ORAPERTS (ORAcle xPERTS)
>
> How can I define a CHECK CONSTRAINT on a table for a field like zip
> code....?
>
> Here is what I am doing:
> create table test
> (
> state varchar2(5) check (state
> in('AL','AK','AZ','AR','CA','CO','CT','DE'))
>
> )
>
> but it seems that it freaks out....wonder why...? I tried using DOUBLE
> QUOTES also but in vain....what is a correct way?
>
> THANKS!
Just watch your syntax :

This will work

create table test( state varchar2(5) constraint test_chk CHECK(STATE IN('AL','AK','AZ','AR','CA','CO','CT','DE'))); Table created.

You can test it by inserting an invalid value:

SQL> INSERT INTO TEST VALUES('YY');
INSERT INTO TEST VALUES('YY')
*
ERROR at line 1:
ORA-02290: check constraint (STEVE.TEST_CHK) violated

I hope this helps,

Steve Received on Mon Sep 08 2003 - 17:04:55 CEST

Original text of this message