开发者

Oracle SQL how to find out which table has the following two columns?

I know of a statement that I can issue to find out the table with the column I am looking for:

SELECT DISTINCT(table_name)
  FROM all_tab_cols 
 WHERE column_name 开发者_如何学Python= 'EMP_ID';

However, how should I modify this so that I may find the table that has both say EMP_ID and EMP_NAME?


Use:

  SELECT table_name
    FROM all_tab_cols 
   WHERE column_name IN ('EMP_ID', 'EMP_NAME')
GROUP BY table_name
  HAVING COUNT(DISTINCT column_name) = 2

The count comparison must equal the number of parameters defined in the IN clause.

...but this is a safer means of determining the table in case their are duplicates:

  SELECT table_name
    FROM all_tab_cols 
   WHERE column_name IN ('EMP_ID', 'EMP_NAME')
GROUP BY table_name, owner
  HAVING COUNT(column_name) = 2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜