RA-00904即使存在列名也无效标识符错误

时间:2012-04-19 17:24:41

标签: oracle oracle10g

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

2 个答案:

答案 0 :(得分:1)

USING子句中,您正在从表SELECT开始CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATEDUAL。此表只有一列DUMMY,因此出错。

答案 1 :(得分:1)

问题似乎与USING子句中的查询有关。 CUSTOMER_IDINVOICE_NUMBERINVOICE_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'

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