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 » 

Exceptions:
  1. Build-in Exceptions
  2. ZERO_DIVIDE Exception
  3. DUP_VAL_ON_INDEX Exception
  4. INVALID_NUMBER Exception
  5. OTHERS Exception
Related: