Constraint Violation Exception ORA-00001 Constraint Violation Exception ORA-00001 oracle oracle

Constraint Violation Exception ORA-00001


A unique constraint enforces, well, uniqueness. It will allow nulls, unlike a primary key constraint.

Your error means that you are inserting duplicate data when the database has been configured to explicitly prohibit that.

You can find out what constraints are on a table by running the following query on all_constraints. The link decodes the column CONSTRAINT_TYPE, for instance P is a primary key and U a unique key.

select *  from all_constraints uc where uc.table_name = 'MY_TABLE'   and owner = 'DBSCHEMA'

To find out what columns are in a constraint use all_cons_columns instead, or combining the two into one query:

select uc.*, ucc.column_name, ucc.position  from all_constraints uc  join all_cons_columns ucc    on uc.owner = ucc.owner   and uc.table_name = ucc.table_name   and uc.constraint_name = ucc.constraint_name where uc.table_name = 'MY_TABLE'   and uc.owner = 'DBSCHEMA'

To either query you can add the additional condition and constraint_name = 'IDX_CO_DETAILS' to find out details of the specific constraint that seems to be causing your problem.


Your comment is a little surprising for a couple of reasons. Even a system created constraint, for instance one that was defined in-line when the table was created without a name being specified should show up. Also, the constraint name IDX... implies that it's an index.

IF you run the following query it should tell you if the object exists in the database:

select *  from all_objects where object_name = 'IDX_CO_DETAILS'

I would expect that the OBJECT_TYPE returned by this query is 'INDEX'.

Following on from that the following query will return every index with that name, the type of index, the table it is associated with and the owner of that table.

select *  from all_indexes where index_name = 'IDX_CO_DETAILS'

Judging by your error I would further expect that the column UNIQUNESS returned by this query is 'UNIQUE'.

This should help you track down the object.

You can also use the system package dbms_metadata to track down the DDL of the object; be careful it returns a clob.

select dbms_metadata.get_ddl('INDEX','IDX_CO_DETAILS', schema => 'DBSCHEMA')   from dual

the parameter schema is optional.