Home / Oracle Errors / ORA-00001

ORA-00001

Unique constraint violated

What it means

An INSERT or UPDATE tried to create a duplicate value in a column or set of columns that must be unique.

Common causes

How to fix it

  1. Read the constraint name in the error message and find its columns: SELECT column_name FROM dba_cons_columns WHERE constraint_name='<NAME>';
  2. Find the existing row with the same key and decide whether to update it instead (use MERGE)
  3. If a sequence feeds the key, move it above the current maximum: ALTER SEQUENCE <seq> RESTART START WITH <n>; (21c and later) or drop and recreate it

How to prevent it

Use MERGE for upserts, keep sequences owned by one process, and handle the error in application code.

Still stuck? Ask the community in Q&A.

Get the weekly Vismo digestNew Oracle articles and Q&A in your inbox. No spam.

One email a week. Unsubscribe any time.