Oracle SQL: selecting from all_tab_columns does not find existing column

和自甴很熟 提交于 2019-12-10 17:17:34

问题


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:


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';



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/17364870/oracle-sql-selecting-from-all-tab-columns-does-not-find-existing-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!