Database Error
ORA-01502: index contains duplicate key values starting from row 1
What This Error Means
This error occurs when trying to create an index on a column that contains duplicate values. In an index, each value must be unique, but if duplicate values exist in the column, this error is thrown.
Why It Happens
This error typically happens when trying to create an index on a column that contains duplicate values, often due to a database design flaw or data entry error. It can also occur when trying to rebuild or rebuild and reorganize an index that contains duplicate values.
How to Fix It
- 1To fix this error, you can either: 1. Create a new column that contains a unique identifier for each row, and create an index on that column instead. 2. Remove the duplicate values from the column before creating the index. 3. Use a function-based index, where you create an index on a function that returns a unique value, such as a hash function.
Example Code Solution
❌ Before (problematic code)
SQL
CREATE INDEX idx_name ON table_name (column_name);✅ After (fixed code)
SQL
CREATE TABLE table_name (
id NUMBER PRIMARY KEY,
name VARCHAR2(50) NOT NULL
);
CREATE INDEX idx_name ON table_name (id);Fix for ORA-01502: index contains duplicate key values starting from row 1
Browse Related Clusters
Related SQL Errors
Related SQL Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error