Recursively list concents of Oracle's DBA_DEPENDENCIES view

妖精的绣舞 提交于 2019-12-06 01:33:13
Ollie

You want to specify the NOCYCLE keyword after your CONNECT BY:

i.e.

SELECT NAME, 
       TYPE, 
       REFERENCED_NAME, 
       REFERENCED_TYPE 
  FROM DBA_DEPENDENCIES 
 WHERE OWNER='FOO' 
   AND NAME='VIEW_01' 
CONNECT BY NOCYCLE
  PRIOR REFERENCED_NAME = NAME;

There is more info on NOCYCLE and the "CONNECT_BY_ISCYCLE" keywords here: http://www.dba-oracle.com/t_advanced_sql_connect_by_loop.htm

and here: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns001.htm

Hope it helps...

EDIT: After comments, you have missed the START WITH clause.

SELECT NAME, 
       TYPE, 
       REFERENCED_NAME, 
       REFERENCED_TYPE 
  FROM DBA_DEPENDENCIES 
 WHERE OWNER='FOO' 
 START WITH NAME='VIEW_01' 
CONNECT BY NOCYCLE
  PRIOR REFERENCED_NAME = NAME;

BTW, keeping the OWNER='FOO' where clause limits any dependencies returned to just FOO's object so you may possibly miss dependencies from other schemas.

Edit 2: The primary key of a table of view is owner, name thus the select should start with both and connect by both. You can use where to filter out desired results.

SELECT OWNER, NAME, TYPE,  
   REFERENCED_OWNER,
   REFERENCED_NAME, 
   REFERENCED_TYPE 
FROM DBA_DEPENDENCIES 
-- where referenced_type='TABLE'
START WITH owner = 'FOO' AND NAME='VIEW_01' 
CONNECT BY NOCYCLE
   PRIOR REFERENCED_NAME = NAME
   AND PRIOR REFERENCED_OWNER = OWNER;

as Ollie said, This is as the same:
This query resolves all deps starting with MYPROC as root of the tree.

SELECT A.NAME,
   A.TYPE,
   A.REFERENCED_OWNER,
   A.REFERENCED_NAME,
   A.REFERENCED_TYPE,
   A.REFERENCED_LINK_NAME,
   A.SCHEMAID  FROM USER_DEPENDENCIES A
 CONNECT BY PRIOR REFERENCED_NAME = A.NAME
 START WITH A.NAME = 'MYPROC'ORDER BY 1, 2, 3, 4
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!