ORACLE SQL MERGE语句中的错误

时间:2014-12-11 21:50:25

标签: oracle oracle11g oracle-sqldeveloper

我试图在Oracle 11g中执行以下代码,并遇到错误..

MERGE INTO EMP_COPY4 C
USING (SELECT E.EMPLOYEE_ID, E.FIRST_NAME, E.LAST_NAME, E.EMAIL, E.COMMISSION_PCT FROM EMPLOYEES) E
ON (C.EMPLOYEE_ID = E.EMPLOYEE_ID)
WHEN MATCHED THEN
UPDATE SET
C.FIRST_NAME = E.FIRST_NAME,
C.LAST_NAME = E.LAST_NAME,
C.EMAIL = E.EMAIL,
C.COMMISSION_PCT = E.COMMISSION_PCT
DELETE WHERE (E.COMMISSION_PCT IS NOT NULL)
WHEN NOT MATCHED THEN
INSERT VALUES (E.EMPLOYEE_ID, E.FIRST_NAME, E.LAST_NAME, E.EMAIL, E.COMMISSION_PCT);       

EMP_COPY4是EMPLOYEES的副本表,只有以下列EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,COMMISSION_PCT

我尝试在某些条件下将它们合并,但是ORACLE会发现错误

Error starting at line : 405 in command -
MERGE INTO EMP_COPY4 C
USING (SELECT E.EMPLOYEE_ID, E.FIRST_NAME, E.LAST_NAME, E.EMAIL, E.COMMISSION_PCT FROM EMPLOYEES) E
ON (C.EMPLOYEE_ID = E.EMPLOYEE_ID)
WHEN MATCHED THEN
UPDATE SET
C.FIRST_NAME = E.FIRST_NAME,
C.LAST_NAME = E.LAST_NAME,
C.EMAIL = E.EMAIL,
C.COMMISSION_PCT = E.COMMISSION_PCT
DELETE WHERE (E.COMMISSION_PCT IS NOT NULL)
WHEN NOT MATCHED THEN
INSERT VALUES (E.EMPLOYEE_ID, E.FIRST_NAME, E.LAST_NAME, E.EMAIL, E.COMMISSION_PCT)
Error at Command Line : 406 Column : 66
Error report -
SQL Error: ORA-00904: "E"."COMMISSION_PCT": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

第405行是语句的开头,第406行是第二行。

你能帮我弄清楚为什么会出现这样的错误吗?

1 个答案:

答案 0 :(得分:1)

用2-d替换 任

USING (SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, COMMISSION_PCT FROM EMPLOYEES) E

USING (SELECT E.EMPLOYEE_ID, E.FIRST_NAME, E.LAST_NAME, E.EMAIL, E.COMMISSION_PCT FROM EMPLOYEES E) E

如果表没有别名

,则不能在SELECT列表中使用别名