SQL MERGE INTO( has issue when trying to insert into database by using subquery) -
merge dwcust dc using a2custmelb cm on (dc.firstname=cm.fname , dc.surname=cm.sname , dc.postcode=cm.postcode) when matched update set dc.dwsourceidmelb=cm.custid when not matched insert (dwcustid, dwsourceidmelb, firstname, surname, gender, phone, postcode, city, state, custcatname) values (dwcust_seq.nextval, cm.custid, cm.fname, cm.sname, upper(cm.gender), cm.phone, cm.postcode, cm.city, cm.state, (select cc.custcatname a2custcategory cc cm.custcatcode = cc.custcatcode ) );
error report -
sql error: ora-00904: "cm"."custcatcode": invalid identifier
- 00000 - "%s: invalid identifier"
how can fix error? there column called custcatcode in a2custmelb database.
thanks.
you can't use select merge insert, move join using:
merge dwcust dc using (select a2custmelb.*, cc.custcatname a2custmelb join a2custcategory cc on cm.custcatcode = cc.custcatcode ) cm on (dc.firstname=cm.fname , dc.surname=cm.sname , dc.postcode=cm.postcode) when matched update set dc.dwsourceidmelb=cm.custid when not matched insert (dwcustid, dwsourceidmelb, firstname, surname, gender, phone, postcode, city, state, custcatname) values (dwcust_seq.nextval, cm.custid, cm.fname, cm.sname, upper(cm.gender), cm.phone, cm.postcode, cm.city, cm.state, cm.custcatname );
Comments
Post a Comment