Du måste definiera en kapslad PL/SQL
Blockera och hantera undantag i EXCEPTION BLOCKERA som WHEN DUP_VAL_ON_INDEX
...
Det borde INTE vara IF DUP_VAL_ON_INDEX
Declare
violation_of_constraint EXCEPTION;
BEGIN
BEGIN
-- (A FEW INSERTS HERE: A, B, C)
SAVEPOINT X;
-- (ANOTHER INSERT HERE: D)
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
ROLLBACK TO X;
COMMIT;
RAISE violation_of_constraint;
END;
EXCEPTION
WHEN violation_of_constraint THEN
DBMS_OUTPUT.PUT_LINE('Value already exists');
COMMIT;
END;
/