Question

I have a view VW_RFI_APRVD_WORK_DTL when i run

  select * from VW_RFI_APRVD_WORK_DTL

it's returning the row pkg_code but when i execute

  SELECT pkg_code FROM VW_RFI_APRVD_WORK_DTL

it is showing error

  SQL Error: ORA-00904: "PKG_CODE": invalid identifier
  00904. 00000 -  "%s: invalid identifier"
  *Cause:    
  *Action:
  Error starting at line 32 in command:
  SELECT pkg_code FROM VW_RFI_APRVD_WORK_DTL
  Error at Command Line:32 Column:8
  Error report:
  SQL Error: ORA-00904: "PKG_CODE": invalid identifier
  00904. 00000 -  "%s: invalid identifier"
  *Cause:    
  *Action:
Was it helpful?

Solution

If you created the view with a quoted lower-case identifier, or the underlying table with a quoted lower-class table name (depending on what the view is doing), then you will always have to refer to that column in exactly the same way, with the same case and enclosed in double quotes.

create view vw_rfi_aprvd_work_dtl as
select dummy as "pkg_code" from dual;

select * from vw_rfi_aprvd_work_dtl;

pkg_code
--------
X        

The column name appears in lower-case in the headers, which is a bit of a giveaway. If you try to select that column without quoting the identifier then you get the ORA-00904:

select pkg_code from vw_rfi_aprvd_work_dtl;

SQL Error: ORA-00904: "PKG_CODE": invalid identifier

But it works if you quote it:

select "pkg_code" from vw_rfi_aprvd_work_dtl;

pkg_code
--------
X        

The documentation recommends that you do not use quoted identifiers. Having to quote things makes the code uglier and harder to read, and it's easy to get the name subtly wrong - easy enough to fix but hard to spot sometimes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top