Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Check Constraints
> > > 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 BerlinReceived on Tue Mar 19 2002 - 11:32:58 CST