Home > Database > Mysql Tutorial > Why Am I Getting ORA-00904: 'invalid identifier' When Querying My Oracle Table?

Why Am I Getting ORA-00904: 'invalid identifier' When Querying My Oracle Table?

Susan Sarandon
Release: 2024-12-23 13:06:12
Original
198 people have browsed it

Why Am I Getting ORA-00904:

ORA-00904 Error: Invalid Identifier

Problem:

When attempting to retrieve data from a table using a simple query where the WHERE clause includes a condition on a column value, you encounter the ORA-00904 error indicating an invalid identifier.

For instance, you have a table named reg1 created with the following columns:

create table reg1 (
  fname varchar2(30),
  lname varchar2(30),
  addr varchar2(30),
  mail varchar2(30),
  occu varchar2(30),
  uname varchar2(30),
  passwd varchar2(30)
);
Copy after login

However, when executing a query to fetch the first name (fname) and last name (lname) of a user with the username 'bbb' like:

select fname, lname
  from reg1
 where uname="bbb";
Copy after login

You receive the error ORA-00904: "bbb": invalid identifier.

Answer:

The error occurs because the value you are comparing against in the WHERE clause is not enclosed in single quotes. In Oracle, when comparing string values, you need to quote them with single quotes to indicate that they are literals.

To resolve the issue, simply add single quotes around the 'bbb' value:

select fname, lname
  from reg1
 where uname='bbb';
Copy after login

With this correction, the query will successfully fetch the data for the user with the username 'bbb', as the comparison is now treated correctly as a literal string comparison.

The above is the detailed content of Why Am I Getting ORA-00904: 'invalid identifier' When Querying My Oracle Table?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template