0

我创建了一个视图,我想找到视图中存在的所有列以及该列所在的源表。例如:

CREATE VIEW myView AS
SELECT  
        firstName,
        middleName,
        you.lastName surName
FROM 
        myTable me
        LEFT OUTER JOIN yourTable you
        ON me.code = you.code

所以在这里我想要如下数据

 ----------------
|SourceTable|Column |
----------------
|me         |firstName|
|me         |middleName|
|you        |lastName|

谁能帮我这个 。PS:我需要它用于Oracle

4

2 回答 2

0

如果列名仅存在于视图中使用的表中的一个表中,那么我们可以通过以下查询找到它。

select table_name, column_name 
from all_tab_columns 
where table_name in ("tables used") 
 and column_name in (select column_name 
                     from all_tab_columns 
                     where table_name = 'view_name');
于 2013-09-20T05:40:08.700 回答
0

可以使用以下查询选择用于创建视图的表:

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

如果视图列与表列具有相同的列名,请尝试以下查询:

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');
于 2013-09-20T05:44:56.507 回答