While creating unique index on a table , got below error.

SQL> create unique index TEST_IDX on TEST5(EMPNO);
create unique index TEST_IDX on TEST5(EMPNO)
*
ERROR at line 1:
ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found

 

Solution:

Find the duplicate rows in the table and delete them.

Use below script to delete the duplicate rows

We can see, for empno=1 and 4 we have duplicate rows. Analyze those rows and delete them remove the duplicates, Once duplicate rows were removed, try to create the index.