1

我有一个 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
4

2 回答 2

3

DBA/USER/ALL_DEPENDENCIES 系统视图具有此信息。http://docs.oracle.com/cd/B28359_01/server.111/b28320/statviews_1066.htm#i1576452

您可以使用 SELECT 中的 CONNECT BY 子句递归地查询它

于 2013-02-14T10:33:48.330 回答
2

用大卫奥尔德里奇的回答解决。我使用了以下查询:

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
于 2013-02-14T12:09:20.433 回答