General discussion

Locked

oracle

By bhagawan ·
How many null values can be insert in a table if there should be unique key?

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Null have no values, so You can insert as many You want

by gu.pipperr In reply to oracle

Testcase:
---
create table t (id number, text varchar2(10));
alter table t add(UNIQUE (text));

---
insert into t (id) values (10);
insert into t (id) values (11);
insert into t (id) values (12);

------
select id,nvl(text,'NULL') from t;
ID NVL(TEXT,'
-------- ----------
10 NULL
11 NULL
12 NULL


---------
insert into t (id,text) values (13,'A');
insert into t (id,text) values (14,'A');

unique constraint (SYS_C0043147) violated

----------

Cause:

Null has no value, if the column is not null you can have null's in the table

----
Solution

set not Null contraint to the column
and set all Null values on a real value.

alter table t modify (text not null);

Collapse -

uniqueness

The word "unique" is defined as ... ?

Back to IT Employment Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums