RA-00904 invalid identifier error even when column name exists

萝らか妹 提交于 2019-12-13 07:14:14

问题


I am running an oracle query in sqldeveloper:

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

I keep getting a RA-00904 invalid identifier for the RA-00904 INVOICE_DATE column, even though that column exists. I have verified by running the describe invoices command and then actually copying the column name:

describe invoices;
Name             
----------------
CUSTOMER_ID      
INVOICE_NUMBER   
INVOICE_DATE   

What's going on here?

RESOLUTION


Vadim and Justin are correct. I fixed the problem by replacing dual with the table name:

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

回答1:


In the USING clause, you're doing a SELECT of columns CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATE from table DUAL. This table has only one column, DUMMY, hence the error.




回答2:


The problem appears to be with the query in your USING clause. CUSTOMER_ID, INVOICE_NUMBER, and INVOICE_DATE are all invalid identifiers because none of them exist in the DUAL table.

select CUSTOMER_ID, INVOICE_NUMBER, INVOICE_DATE 
  from dual 
 where INVOICE_NUMBER = '123'
   and CUSTOMER_ID = '456' 
   and INVOICE_DATE = '19-APR-12'

Unfortunately, it's not obvious to me how to fix the problem because it's not obvious what you are trying to accomplish.



来源:https://stackoverflow.com/questions/10233417/ra-00904-invalid-identifier-error-even-when-column-name-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!