Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Oracle SQL: selecting from all_tab_columns does not find

existing column
Asked 10 years, 4 months ago Modified 5 years ago Viewed 30k times

If I run the following query:

5 select count(*) from all_tab_columns


where column_name = 'foo'
and table_name = 'VIEW0';

I get 0 for a result. I expect 1.

But if I run the following query I get many (expected) rows returned:

select foo from VIEW0;

Why? I'm assuming I'm making some dumb syntax mistake or my understanding is way off.

sql oracle oracle-sqldeveloper

Share Improve this question Follow edited Nov 5, 2018 at 9:28 asked Jun 28, 2013 at 12:35
ZygD lostinthebits
22.5k 40 84 105 661 2 11 24

Shouldn't the value you are searching for in column_name be uppercase? – Joe W Jun 28, 2013 at 12:39

3 Answers Sorted by: Highest score (default)

Probably the reason is that you have case sensitive setting.

Try to add UPPER function as below.


11
select count(*) from all_tab_columns
where column_name = upper('foo')
and table_name = 'VIEW0';

Share Improve this answer Follow edited Jun 28, 2013 at 12:46 answered Jun 28, 2013 at 12:38
Robert
25.5k 8 68 83

Oracle always store column names as well as table names in upper case; so upper is necessary on 'foo'
– Dmitry Bychenko Jun 28, 2013 at 12:45

Thanks! That was it! I will vote it in 4 minutes when I am allowed to. – lostinthebits Jun 28, 2013 at 12:46

@DmitryBychenko I've change the answer. Thanks! – Robert Jun 28, 2013 at 12:46
1 The upper on column_name and table_name are unneeded and really the other two uppers are unneeded as one is
already all uppercase and its easy to just change the the other one to uppercase and not have to do any work on the
system to change the case. – Joe W Jun 28, 2013 at 12:48

Wait is there a difference between accepting the answer and voting for it? – lostinthebits Jun 28, 2013 at 12:49

ALL_TAB_COLUMNS describes the columns of the tables, views, and clusters accessible to the current
user. Check, if user under whom you running this query have access to the desired table.
1
Share Improve this answer Follow answered Jun 28, 2013 at 12:46
Mikhail
1,560 2 13 13

It appears, at least in 11g, that you cannot access the data dictionary tables from PL/SQL. Running any
select on all_tab_columns inside PL/SQL always returns no results. Attempting to access dba_tab_columns
0 will not compile, because the compiler believes the table (or view) does not exist.

I'd love to see how to access the data dictionary from PL/SQL.

Share Improve this answer Follow answered Jun 30, 2017 at 17:16
Pete Nelson
1

You might also like