Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: PL/SQL: how to let it continue when unique constraint violated
In article <867gaa$g26$1_at_justice.csc.cuhk.edu.hk>, Jeff
<kit_at_cintec.cuhk.edu.hk> writes
>Hi,
>
>How to let the PL/SQL continue to run when I select some rows and insert
>them to another table, without quited immediately when unique constraint is
>violated, such that the other records can still be inserted?
>
You need to look at EXCEPTIONs and DUP_VAL_ON_INDEX
e.g.
PROCURE my_procedure
IS
CURSOR my_from_table
IS
SELECT x,y
FROM table1
;
BEGIN
FOR v_data IN my_from_table LOOP
BEGIN INSERT INTO my_to_table VALUES (v_data.x, v_data.y); EXCEPTION WHEN DUP_VAL_ON_INDEX THEN -- -- ignore any duplicates -- NULL; WHEN OTHERS THEN RAISE; END;
--
Andy Hardy. PGP key available on request