0% found this document useful (0 votes)
32 views

SQL - Oracle - Query Runs Successfully, But The Column Name Is Not Available - Stack Overflow

The query runs successfully but the column name is not available in the table. When the inner query is run separately, it throws an error saying the column name is invalid. This happens because the column likely exists in the outer table but not the inner table being queried. Adding table aliases prevents referencing ambiguous column names and would cause the query to error as expected.

Uploaded by

soydeyudru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

SQL - Oracle - Query Runs Successfully, But The Column Name Is Not Available - Stack Overflow

The query runs successfully but the column name is not available in the table. When the inner query is run separately, it throws an error saying the column name is invalid. This happens because the column likely exists in the outer table but not the inner table being queried. Adding table aliases prevents referencing ambiguous column names and would cause the query to error as expected.

Uploaded by

soydeyudru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Oracle : Query Runs Successfully, but the column name is not

available
Asked 5 years, 11 months ago Modified 5 years, 11 months ago Viewed 283 times

In our application Oracle(11g and 12C) , I'm facing a weird Issue as below.

When I run the below query in Oracle DB it runs successfully and gives me output.
2
select * from table1 where col1 in (select col2 from table2 ) ;

But when I run the below inner query alone it throws the error:

select col2 from table2 ORA-00904: "COL2": invalid identifier

When I described the table table2, Col2 is not there. The error is expected. But the previous query
executes successfully which is my concern.Could some one explain me this behavior?

sql oracle oracle11g oracle12c

Share Improve this question Follow edited Nov 27, 2017 at 12:13 asked Nov 27, 2017 at 11:20
DineshDB Vinoth Karthick
6,038 8 33 49 995 10 29

1 Answer Sorted by: Highest score (default)

Always, I repeat always give and use table aliases. You will never run into troubles and won't face such
scenarios: Now run below query again in same DB, I'm sure it will throw some error:
2
select * from table1 a where a.col1 in (select b.col2 from table2 b) ;

Now notice, all I did was give tables aliases. What most probably happening here is that table1 has a
column named 'col2' and sub-query is referencing to that one. That's why it runs fine and doesn't show
any error.

Share Improve this answer Follow answered Nov 27, 2017 at 11:37
Niranjan Rajawat
553 2 9

You might also like