How to Fix ORA-00904: Invalid Identifier in Oracle

Find the name Oracle cannot resolve in ORA-00904 and fix typos, case-sensitive quoted columns, and misplaced aliases.

ORA-00904 means the statement uses a name that Oracle cannot find among the columns, aliases, or functions available at that point. The name is shown in the message, in uppercase and double quotes, which is usually all you need to spot the problem: a typo, a column that does not exist in that table, a column created with quotes and mixed case, or an alias used where it is not visible.

Reproduce the Error

Example:

create table demo_products (product_id number, product_name varchar2(40), "Unit Price" number);
insert into demo_products values (1, 'Laptop', 899);

select product_nam from demo_products;                 -- misspelled column
select unit_price from demo_products;                  -- the column was created with quotes
select product_id, product_name total from demo_products order by totl;   -- alias misspelled

Output:

Table DEMO_PRODUCTS created.

1 row inserted.

Error starting at line : 4
In command -
select product_nam from demo_products
Error at Command Line : 4 Column : 8
Error report -
SQL Error: ORA-00904: "PRODUCT_NAM": invalid identifier

Error starting at line : 5
In command -
select unit_price from demo_products
Error at Command Line : 5 Column : 8
Error report -
SQL Error: ORA-00904: "UNIT_PRICE": invalid identifier

Error starting at line : 6
In command -
select product_id, product_name total from demo_products order by totl
Error at Command Line : 6 Column : 67
Error report -
SQL Error: ORA-00904: "TOTL": invalid identifier
  • PRODUCT_NAM is a typo for PRODUCT_NAME.
  • "Unit Price" was created in double quotes, so it is case-sensitive and contains a space: unit_price is a different name.
  • TOTL is a misspelled column alias in ORDER BY.

Fix: Use the Real Column Name

USER_TAB_COLUMNS lists the columns exactly as stored. A name created in quotes must be written in quotes, with the same case, every time:

Example:

-- check the real column names
select column_name from user_tab_columns where table_name = 'DEMO_PRODUCTS' order by column_id;

select product_name, "Unit Price" as unit_price from demo_products;

Output:

COLUMN_NAME
_______________
PRODUCT_ID
PRODUCT_NAME
Unit Price

no rows selected

Other Common Causes

  • A column alias used in the WHERE clause of the same query: WHERE is evaluated before the select list. Repeat the expression, or select from a subquery that defines the alias. Oracle AI Database 26ai accepts aliases in GROUP BY and HAVING; older releases raise ORA-00904 there too.
  • A function that does not exist or is not accessible, such as a misspelled built-in or a function in another schema without a grant.
  • Double quotes around a text value: "Delhi" is a column name, while 'Delhi' is a string.

Things to Know

  • Unquoted names are stored in uppercase, so Product_Name and product_name are the same column; quoted names are not.
  • Avoid creating tables with quoted names; they force every query to quote them.
  • In PL/SQL, the same mistake inside a SQL statement is reported as ORA-00904 when the block is compiled or run.

Related Guides

Conclusion

ORA-00904 names an identifier Oracle cannot resolve. Compare it with the real column names in USER_TAB_COLUMNS, quote names that were created in quotes, use single quotes for text, and do not use select-list aliases in WHERE.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted