Ich habe zwei Tabellen, adv_institution
und institution
. Oracle MERGE verwenden, um Back-zu füllen Datensätze adv_institution
von institution
institution
hat 5000+ Reihen, während adv_institution
1400+ORA-00001: eindeutige Einschränkung (MYUSER.ADI_PK) verletzt
hat ich will. Diese zwei Tabellen haben ungefähr vier Felder, die ich zum Füllen verwenden kann.
Hier ist meine ganze MERGE-Anweisung
merge into
adv_institution to_t
using (
select
uni.*,
adv_c.country_cd as con_code_text
from
(
select
institution_cd,
name,
institution_status,
country_cd
from
institution uni
where
uni.institution_status = 'ACTIVE' and
uni.country_cd is not null
group by
institution_cd,
name,
institution_status,
country_cd
order by
name
) uni,
country_cd c_cd,
adv_country adv_c
where
uni.country_cd = c_cd.country_cd and
c_cd.description = adv_c.country_cd
) from_t
on
(
to_t.VENDOR_INSTITUTION_CD = from_t.INSTITUTION_CD or
to_t.INSTITUTION_CD = from_t.NAME
)
WHEN NOT MATCHED THEN INSERT (
to_t.INSTITUTION_CD,
to_t.INSTITUTION_NAME,
to_t.SHORT_NAME,
to_t.COUNTRY_CD,
to_t.NOTE,
to_t.UNIT_TERMINOLOGY,
to_t.COURSE_TERMINOLOGY,
to_t.CLOSED_IND,
to_t.UPDATE_WHO,
to_t.UPDATE_ON,
to_t.CALLISTA_INSTITUTION_CD
)
VALUES (
from_t.NAME,
from_t.NAME,
'',
from_t.con_code_text,
'',
'UNIT',
'COURSE',
'N',
'MYUSER',
SYSDATE,
from_t.institution_cd
);
Der Fehler habe ich ist
Fehlerbericht - ORA-00001: eindeutige Einschränkung (MYUSER.ADI_PK) verletzt
ADI_PK
Mittel adv_institution.institution_cd
ist ein Primärschlüssel und muss eindeutig sein.
Das ist, weil in WHEN NOT MATCHED THEN INSERT
gibt es eine Insert-Anweisung. Ich füge from_t.NAME
in to_t.INSTITUTION_CD
ein.
Es sieht aus wie from_t.NAME
den gleichen Wert mindestens zweimal hat, wenn sie in to_t.INSTITUTION_CD
Einfügen Aber ich habe eine Gruppe Aussage sicher from_t.NAME
zu machen, ist einzigartig:
(
select
institution_cd,
name,
institution_status,
country_cd
from
institution uni
where
uni.institution_status = 'ACTIVE' and
uni.country_cd is not null
group by
institution_cd,
name,
institution_status,
country_cd
order by
name
) uni
Ich bin nicht sicher, ich verstehe das Problem richtig. Ich habe alles versucht, was ich kann, aber immer noch kein Glück.