How can I find the underlying column and table name for an Oracle view?

前端 未结 7 1845
余生分开走
余生分开走 2021-01-23 05:34

This sounds like it should be simple to do but not so! There is no Oracle (meta-data) view that I can find that gives the underlying column and table name for an Oracle view col

7条回答
  •  心在旅途
    2021-01-23 06:05

    Tables used to created the view can be selected using the query:

    select 
      name , 
      type , 
      referenced_name , 
      referenced_type
    from 
      user_dependencies 
    where 
      name = 'VIEW_NAME' and 
      type = 'VIEW' and  
      referenced_type = 'TABLE';
    

    If view columns have the same column name of table column, then please try the below query:

    select 
      distinct table_name, column_name 
    from 
      all_tab_columns 
    where table_name in (select
                            referenced_name
                          from 
                            user_dependencies 
                          where 
                            name = 'VIEW_NAME' and 
                            type = 'VIEW' and  
                            referenced_type = 'TABLE') 
     and column_name in (select 
                            column_name 
                         from 
                            all_tab_columns 
                         where 
                            table_name = 'VIEW_NAME');
    

提交回复
热议问题