I need to insert some field in a table. The table:
CREATE TABLE RADAR(
ctfoto VARCHAR2(5),
pkradar NUMBER(3,0),
sradar VARCHAR2(3),
limitvelctera NUMBER(3,0),
limitvelradar NUMBER(3,0),
CONSTRAINT radar_pk PRIMARY KEY(ctfoto, pkradar, sradar)
);
The insert operation:
INSERT INTO RADAR(ctfoto, pkradar, sradar, limitvelctera, limitvelradar)
SELECT distinct carretera_foto, pto_km_radar, sentido_radar, limit_vel_ctera, limit_vel_radar FROM gotcha
The error:
ORA-00001: unique constraint (USER4704.RADAR_PK) violated
Please help.
DISTINCTapplies to the entire set of columns you are selecting.In all probability, you have rows in
GOTCHAthat have the samecarretera_foto,pto_km_radar, andsentido_radarvalues but different values for one or both of the other two columns (limit_vel_cteraandlimit_vel_radar). TheDISTINCTin yourSELECTcannot eliminate either of the rows because at least one value is different but the primary key constraint on theRADARtable rejects rows where the first three columns are identical.