5

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.

1
  • Shouldn't the value you are searching for in column_name be uppercase? Commented Jun 28, 2013 at 12:39

3 Answers 3

11

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';
Sign up to request clarification or add additional context in comments.

6 Comments

Oracle always store column names as well as table names in upper case; so upper is necessary on 'foo'
Thanks! That was it! I will vote it in 4 minutes when I am allowed to.
@DmitryBychenko I've change the answer. Thanks!
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.
Wait is there a difference between accepting the answer and voting for it?
|
1

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.

Comments

0

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 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.