Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding Not Null constraint to a column which has null values

EV259Apr 30 2014 — edited Apr 30 2014

All,

Could you please suggest me, How to add not null constraint to an existing column which has null values?

SQL> create table nn ( n number, s varchar2(10));

Table created.

SQL> insert into nn values (1,'test');

1 row created.

SQL> insert into nn values (2,'');

1 row created.

SQL> commit;

Commit complete.

SQL> alter table nn modify n number not null;

Table altered.

SQL> desc nn;

Name                                      Null?    Type

----------------------------------------- -------- ----------------------------

N                                         NOT NULL  NUMBER

S                                                          VARCHAR2(10)

SQL> alter table nn modify n number null;

Table altered.

SQL> desc nn;

Name                                      Null?    Type

----------------------------------------- -------- ----------------------------

N                                                  NUMBER

S                                                  VARCHAR2(10)

SQL> alter table nn modify s varchar2(10) not null;

alter table nn modify s varchar2(10) not null

*

ERROR at line 1:

ORA-02296: cannot enable (SCOTT.) - null values found

SQL>

Thanks

This post has been answered by Solomon Yakobson on Apr 30 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 28 2014
Added on Apr 30 2014
5 comments
1,850 views