I got a "ORA-00001: unique constraint (user.indexname) violated" error and it surprises me, as I don't see how that error can happen on an index (that is not unique).
The message:
ORA-00001: unique constraint (USER.TAB_LIST_PROP_PROPID_IDX) violated
db version (excerpt from lsinventory):
Oracle Database 11g | 11.2.0.4.0 |
There are 1 products installed in this Oracle Home.
Interim patches (2) :
Patch 17501296 | : applied on Mon Jun 15 19:02:17 CEST 2020 |
Unique Patch ID: 18802658
Created on 10 Apr 2015, 16:40:58 hrs PST8PDT
Bugs fixed:
Patch 28204707 | : applied on Mon Jun 15 18:55:06 CEST 2020 |
Unique Patch ID: 22456102
Patch description: "Database Patch Set Update : 11.2.0.4.181016 (27734982)"
Created on 20 Sep 2018, 00:18:41 hrs PST8PDT
code excerpt:
CREATE TABLE TAB_LIST_PROP (
ListId INTEGER NOT NULL ,
PropId INTEGER NOT NULL );
ALTER TABLE TAB_LIST_PROP ADD CONSTRAINT TAB_LIST_PROP_FK_LIST FOREIGN KEY
(ListId) REFERENCES TAB_LIST (ListId);
ALTER TABLE TAB_LIST_PROP ADD CONSTRAINT TAB_LIST_PROP_FK_PROP FOREIGN KEY
(PropId) REFERENCES TAB_PROP (PropId);
CREATE INDEX TAB_LIST_PROP_IDX ON TAB_LIST_PROP (ListId ASC);
CREATE INDEX TAB_LIST_PROP_PROPID_IDX ON TAB_LIST_PROP (PropId) ; -- <----- this is the index from the error message
--------------
create package body foo is
c_true constant char(1) := '1';
c_false constant char(1) := '0';
procedure createListEntry(TopicId INTEGER,
p_1 number,
p_2 number,
p_3 number,
PropId number,
p_id out number
)
is
nextID NUMBER(19,0);
begin
SELECT TAB_LIST_SEQ.nextVal into nextID FROM dual;
insert into TAB_LIST (ListId,
TopicId,
more,
columns,
here,
PropId)
values (nextID,
TopicId,
p_1,
p_2,
p_3,
PropId);
p_id := nextID;
INSERT INTO TAB_LIST_FOO ... -- this is very similar to the next INSERT and executes without problems, so it omitted
-- this statement throws the error:
INSERT INTO TAB_LIST_PROP (ListId, PropId) SELECT DISTINCT nextID as ListId, PropId
from TAB_TOPIC
LEFT JOIN u_am ON u_am.TopicId=TAB_TOPIC.TopicId
and u_am.Flag1 /* CHAR(1) */ =c_false and u_am.Flag2 /* CHAR(1) */ =c_true
LEFT JOIN u_oam ON u_oam.oamId=u_am.oamId
and u_oam.Flag1=c_false and u_oam.Flag2=c_true
LEFT JOIN ARPM on u_oam.AppRolPrmId = ARPM.AppRolPrmId
and ARPM.Flag1 = c_false and ARPM.Flag2 = c_true
WHERE TAB_TOPIC.TopicId=createListEntry.TopicId and PropId /* a column in the table ARPM */ is not null;
end;