Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL: selecting from all_tab_columns does not find existing column

If I run the following query:

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.

like image 967
lostinthebits Avatar asked Jun 28 '13 12:06

lostinthebits


2 Answers

Probably the reason is that you have case sensitive setting.

Try to add UPPER function as below.

select count(*) from all_tab_columns
        where column_name = upper('foo')
        and table_name = 'VIEW0';
like image 189
Robert Avatar answered Nov 11 '22 20:11

Robert


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.

like image 29
Mikhail Avatar answered Nov 11 '22 21:11

Mikhail