0

我在 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')
4

2 回答 2

1

在该USING子句中,您正在执行来自 tableSELECT的列。该表只有一列,,因此错误。CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATEDUALDUMMY

于 2012-04-19T17:36:04.327 回答
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'

不幸的是,对我来说如何解决这个问题并不明显,因为你想要完成的事情并不明显。

于 2012-04-19T17:36:22.770 回答