How to ignore unique constraint?

Question:

> How do you ignore the unique constraint error when inserting tables from a
> selected results, such that all records are inserted with duplicates records
> left behind?
>
> Thanks.
>
> Jeff
>

Answer 1:

With pure sql you can not ignore errors but you can use pl/sql with an
exception block like:

begin
open c_select;
loop
  fetch c_select into v_variables;
  exit when c_select%notfound;
  begin
  insert into target_table
    values (v_variables...)
  exception
    dup_val_on_index then null;
  end;  -- of error traping block
end loop ;
end ;

You need to define your variables or use a cursor for loop but this in
the best way I know.

--
Mark D. Powell  -- The only advice that counts is the advice that
 you follow so follow your own advice --

Answer 2:

With Oracle 8.x you can use deferrable constraints (including PRIMARY KEY).
See Oracle 8.x SQL Reference on CONSTRAINT clause and SET CONSTRAINT
command.
 
 
 

Hosted by www.Geocities.ws

1