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

Home -> Community -> Usenet -> c.d.o.server -> Re: Attribute Level Constraint

Re: Attribute Level Constraint

From: Tony Andrews <andrewst_at_onetel.com>
Date: 23 Jun 2006 04:13:44 -0700
Message-ID: <1151061224.064174.243510@u72g2000cwu.googlegroups.com>


Khurram wrote:
> My question Why it is accepting NULL values though i have declared NOT
> NULL to table
> column name??

The constraint says that the COLUMN must not be null:

SQL> INSERT INTO t VALUES (2,NULL);
INSERT INTO t VALUES (2,NULL)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("XX"."T"."NAME")

It does not say that the attributes of the column cannot be null. There is a subtle but real difference between NULL and mytype(NULL,NULL).

However, you can create constraints at the attribute level:

SQL> alter table t add constraint fname_chk check (name.fname is not null);

Table altered.

SQL> alter table t add constraint lname_chk check (name.lname is not null);

Table altered.

SQL> INSERT INTO t VALUES (2,mytype(NULL,NULL)); INSERT INTO t VALUES (2,mytype(NULL,NULL)) *
ERROR at line 1:
ORA-02290: check constraint (XX.LNAME_CHK) violated Received on Fri Jun 23 2006 - 06:13:44 CDT

Original text of this message

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