我在sqldeveloper中运行oracle查询:
merge into invoices c using (select CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATE from dual where INVOICE_NUMBER = '123'
and CUSTOMER_ID = '456' and INVOICE_DATE = '19-APR-12') cd
on (c.INVOICE_NUMBER = cd.INVOICE_NUMBER)
when not matched then
insert (c.CUSTOMER_ID, c.INVOICE_NUMBER, c.INVOICE_DATE)
values ('987', '654','179-APR-12')
我一直收到RA-00904 INVOICE_DATE列的RA-00904无效标识符,即使该列存在。我已通过运行describe invoices命令进行验证,然后实际复制了列名:
describe invoices;
Name
----------------
CUSTOMER_ID
INVOICE_NUMBER
INVOICE_DATE
这里发生了什么?
解决方案
Vadim和Justin是对的。我通过用表名替换dual来解决问题:
merge into invoices c using (select CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATE from invoices where INVOICE_NUMBER = '123'
and CUSTOMER_ID = '456' and INVOICE_DATE = '19-APR-12') cd
on (c.INVOICE_NUMBER = cd.INVOICE_NUMBER)
when not matched then
insert (c.CUSTOMER_ID, c.INVOICE_NUMBER, c.INVOICE_DATE)
values ('987', '654','179-APR-12')
答案 0 :(得分:1)
在USING
子句中,您正在从表SELECT
开始CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATE
列DUAL
。此表只有一列DUMMY
,因此出错。
答案 1 :(得分:1)
问题似乎与USING
子句中的查询有关。 CUSTOMER_ID
,INVOICE_NUMBER
和INVOICE_DATE
都是无效的标识符,因为DUAL
表中不存在任何标识符。
select CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATE
from dual
where INVOICE_NUMBER = '123'
and CUSTOMER_ID = '456'
and INVOICE_DATE = '19-APR-12'
不幸的是,对我来说,如何解决这个问题并不明显,因为你想要完成的事情并不明显。