DUP_VAL_ON_INDEX Exception
DUP_VAL_ON_INDEX
exception happens when storing duplicate values in a column with a unique index.
CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
SAL NUMBER(7, 2),
DEPTNO NUMBER(2),
CONSTRAINT emp_pk PRIMARY KEY (empno)
);
INSERT INTO EMP VALUES (1, 'SMITH', 'CLERK', 800, 20);
SQL> BEGIN
2 INSERT INTO emp (empno, ename) VALUES (1, 'Greg');
3 EXCEPTION
4 WHEN DUP_VAL_ON_INDEX THEN
5 DBMS_OUTPUT.PUT_LINE('Duplicate value on an index');
6 END;
7 /
Duplicate value on an index
PL/SQL procedure successfully completed.
SQL>
Home »
Oracle »
PL/SQL »
Oracle »
PL/SQL »
Exceptions:
- Build-in Exceptions
- ZERO_DIVIDE Exception
- DUP_VAL_ON_INDEX Exception
- INVALID_NUMBER Exception
- OTHERS Exception
Related: