用于显示View元数据的Oracle查询

时间:2014-06-06 13:16:55

标签: sql oracle oracle11g

由于历史原因,我们有一组视图调用其他物化视图或表(本地或通过DB链接)

我需要生成一个报告,列出每个视图正在调用的所有表或MV。我设法创建此查询:

  SELECT *
  FROM cols c, obj o
  WHERE c.TABLE_NAME = o.object_name
  AND o.object_type = 'VIEW'     
  ORDER BY c.table_name, c.column_id;

它几乎在那里,但仍然缺少视图选择的表/ MV名称, 我们选择什么类型的东西(MV或表,通过DB链接或同义词)

任何人都可以提供帮助

2 个答案:

答案 0 :(得分:1)

我觉得这样......

我将其展开以查看所有对象,然后按架构(所有者)进行限制。

 SELECT O.Owner, O.object_name, C.ColumN_Name, C.Data_Type, O.Object_type, O.Object_Type, 
    AD.Referenced_name, AD.Referenced_Type
  FROM ALL_TAB_COLS c
  INNER JOIN ALL_OBJECTS O
    ON c.TABLE_NAME = o.object_name
    and C.Owner = O.Owner
  INNER JOIN ALL_DEPENDENCIES AD
    on AD.Name = O.Object_Name
    and AD.Owner = O.Owner
  WHERE  o.object_type = 'VIEW' 
  and O.owner = user
  ORDER BY c.table_name, c.column_id;

答案 1 :(得分:1)

我使用了这种类型的查询的变体来查看我的视图依赖项。

SELECT dd.owner view_owner,
  dd.NAME view_name,
  dd.referenced_owner,
  dd.referenced_name,
  dd.referenced_object_name
FROM
  (SELECT dep.owner,
    dep.NAME,
    dep.referenced_owner,
    dep.referenced_name,
    dep.TYPE,
    dep.owner
    || '.'
    || dep.NAME object_name,
    dep.referenced_owner
    || '.'
    || dep.referenced_name referenced_object_name
  FROM dba_dependencies dep
  INNER JOIN dba_objects obj
  ON dep.referenced_name   = obj.object_name
  AND dep.referenced_owner = obj.owner
  WHERE dep.TYPE          IN ('VIEW','MATERIALIZED VIEW', 'TABLE')
  AND obj.object_type     IN ('VIEW','MATERIALIZED VIEW', 'TABLE')
  ) dd
  START WITH dd.owner         = :l_owner
AND dd.NAME                   = :l_view
AND dd.TYPE                   = 'VIEW'
  CONNECT BY NOCYCLE PRIOR 1  =1
AND PRIOR dd.referenced_owner =dd.owner
AND PRIOR dd.referenced_name  =dd.NAME

此查询仅从视图(:l_owner,:l_view)开始,从层次结构角度循环遍历依赖关系