Bad Programmer
Bad Programmer

Reputation: 3752

RA-00904 invalid identifier error even when column name exists

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

Upvotes: 0

Views: 5384

Answers (2)

Justin Cave
Justin Cave

Reputation: 231781

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.

Upvotes: 1

Vadim K.
Vadim K.

Reputation: 2446

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.

Upvotes: 1

Related Questions