Oracle查询某字段在哪些表中有

在网上查的sql语句一般都是:

 select TABLE_NAME  
 from user_tab_columns  
 where COLUMN_NAME='CNAME'

 可是在user_tab_columns表中查询某字段在哪些表中出现过的时候,会把视图也查出来,还会查出一个莫名其妙的一串字符,与需求不符,

之后又认识了另一个表:user_tables,这个表能够查询出用户有那些表。

user_tab_columns与user_tables的inner join即可查询出某字段在哪些表中有了。

select t.table_name 
from user_tables t  
inner join  (
  select TABLE_NAME  
  from user_tab_columns  
  where COLUMN_NAME='CNAME'
) b on t.TABLE_NAME=b.TABLE_NAME;

 

猜你喜欢

转载自hejiawangjava.iteye.com/blog/2397279
今日推荐