Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Check Constraints

Re: Check Constraints

From: Knut Talman <knut.talman_at_mytoys.de>
Date: Tue, 19 Mar 2002 18:32:58 +0100
Message-ID: <3C97764A.764929F4@mytoys.de>


> > > How do I check to make sure a attribute of type VARCHAR2 is greater
> > > than 2 characters? For example if I create a table and the attribute
> > > is:
> > >
> > > organization VARCHAR2(50) NOT NULL,
> > >
> > > and I also want it to always be greater than 2 characters.
> > >
> > > Thanks.
>
> Isn't there an easier way to do this like if I want to check for a
> number greater than 3 I could do:
> CHECK constraint (organization > 3);
> or if I wanted to check to ensure users put a @ in a field called
> email I could say:
> email VARCHAR2(20),
> CONSTRAINT email_check
> CHECK (email LIKE ('%@%');

So why don't you use a check constraint like

CREATE TABLE testcheck (

	id 	     NUMBER(10),
	organization VARCHAR2(50) NOT NULL,
	CONSTRAINT cnstrt_org_length CHECK(LENGTH(organization)>2));

HTH, Knut

-- 
Dipl.-Inform. Knut Talman                       Fon +49.30.72 62 01 411
myToys.de GmbH                                  Fax +49.30.72 62 01 222
Schoenhauser Allee 36-39                        Mobil +49.173.671 65 65
D-10435 Berlin
Received on Tue Mar 19 2002 - 11:32:58 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US