我在 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
这里发生了什么?
解析度
瓦迪姆和贾斯汀是正确的。我通过用表名替换 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')