0

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')
Bad Programmer
  • 3,642
  • 13
  • 46
  • 53

2 Answers2

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.

Vadim K.
  • 2,370
  • 18
  • 26
1

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.

Justin Cave
  • 227,342
  • 24
  • 367
  • 384