我有一个Oracle VIEW,我想查找我的视图所依赖的所有表。 可能,我的视图依赖于其他视图:在这种情况下,我想以递归方式导航依赖项并进入表格。
以下是我的架构示例:
CREATE TABLE T1 (A NUMBER);
CREATE TABLE T2 (B NUMBER);
CREATE TABLE T3 (A NUMBER, B NUMBER);
CREATE VIEW V1 AS SELECT * FROM T1;
CREATE VIEW V2 AS SELECT * FROM T2;
CREATE VIEW V3 AS SELECT * FROM V1, V2 UNION ALL SELECT * FROM T3;
这是我想要的输出:
VIEW_NAME TABLE NAME
--------- ----------
V3 T1
V3 T2
V3 T3
答案 0 :(得分:3)
DBA / USER / ALL_DEPENDENCIES系统视图包含此信息。 http://docs.oracle.com/cd/B28359_01/server.111/b28320/statviews_1066.htm#i1576452
您可以使用SELECT
中的CONNECT BY子句递归查询它答案 1 :(得分:1)
解决了David Aldridge的回答。我使用了以下查询:
SELECT CONNECT_BY_ROOT d.name AS view_name, d.referenced_name AS table_name
FROM user_dependencies d
WHERE d.referenced_type = 'TABLE'
START WITH d.name = 'V3' AND d.type = 'VIEW'
CONNECT BY PRIOR d.referenced_name = d.name AND PRIOR d.referenced_type = d.type