【问题标题】:How to get all the table names used in an Oracle view?如何获取 Oracle 视图中使用的所有表名?
【发布时间】:2015-01-04 04:42:50
【问题描述】:

我想获取在 Oracle 视图或 SQL 查询中使用的所有表名的列表。

例如,从下面的查询

select a.col1, b.col2
from first_table a, second_table b;

我想得到这个结果:

first_table
second_table

我有一位客户创建了非常复杂的 SQL 查询作为视图,我希望有一种快速的方法来提取其中使用的所有表。我在 perl 中找到了一种方法,但我想在 SQL 中进行。

【问题讨论】:

    标签: oracle


    【解决方案1】:

    此查询为您提供位于架构 VIEW_OWNER 中的视图 VIEW_NAME 的所有依赖表(及其所有者)

    select ud.referenced_owner tab_owner,
           ud.referenced_name tab_name
    from all_dependencies ud
    where ud.name = 'VIEW_NAME' 
      and ud.type = 'VIEW' 
      and ud.referenced_type = 'TABLE'
      and ud.owner = 'VIEW_OWNER';
    

    如果所有表和视图都在您的架构中,您可以使用 USER_DEPENDENCIES Oracle 字典;如果可以有来自不同架构的表,则可以使用 ALL_DEPENDENCIES。

    【讨论】:

    • 太棒了!这正是我一直在寻找的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 2010-09-17
    • 2011-08-04
    • 1970-01-01
    • 2015-09-13
    相关资源
    最近更新 更多