unique constraint violated [message #218726] |
Fri, 09 February 2007 10:08  |
Duane
Messages: 585 Registered: December 2002
|
Senior Member |
|
|
Is there a way to deterime which value violated the constraint?
When doing a "insert into table (select * from table)" is there a way to determine what value it failed on? A way to print it out in the "exception when others" clause?
Something like:
alter table no_duplicate_names add (
constraint pk_no_duplicate_names
primary key
(name)
using index
BEGIN
insert into no_duplicate_names
(name)
(select name
from duplicate_names)
EXCEPTION
WHEN others
THEN
htp.print('The constraint failed on "insert.value"');
END;
|
|
|
|
|
|
|
|
|
Re: unique constraint violated [message #218745 is a reply to message #218726] |
Fri, 09 February 2007 15:04  |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
handle the dups in the select.
insert into no_duplicate_names (name)
select name from duplicate_names a
where not exists
(select null
from no_duplicate_names b
where a.name = b.name);
No duplicate rows will be inserted.
|
|
|