MERGE INTO DWCUST dc
USING A2CUSTMELB cm
ON (dc.firstname=cm.fname AND dc.surname=cm.sname and dc.postcode=cm.postcode)
WHEN MATCHED THEN UPDATE SET dc.DWSOURCEIDMELB=cm.custid
WHEN NOT MATCHED THEN
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 from a2custcategory cc where cm.custcatcode = cc.custcatcode ) );
错误报告 -
SQL错误:ORA-00904:“CM”。“CUSTCATCODE”:标识符无效
- 00000 - “%s:无效标识符”
醇>
如何修复此错误?在我的A2CUSTMELB数据库中有一个名为CUSTCATCODE的列。
感谢。
答案 0 :(得分:2)
您不能将SELECT与MERGE INSERT一起使用,将连接移动到USING:
MERGE INTO DWCUST dc
USING
(SELECT A2CUSTMELB.*, cc.custcatname
FROM A2CUSTMELB JOIN a2custcategory cc
ON CM.custcatcode = cc.custcatcode
) CM
ON (dc.firstname=CM.fname AND dc.surname=CM.sname AND dc.postcode=CM.postcode)
WHEN MATCHED THEN UPDATE SET dc.DWSOURCEIDMELB=CM.custid
WHEN NOT MATCHED THEN
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 );