Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you programatically identify a stored procedure's dependencies?

Is it possible to write a PL/SQL query to identify a complete list of a stored procedures dependencies? I'm only interested in identifying other stored procedures and I'd prefer not to limit the depth of nesting that it gets too either. For example, if A calls B, which calls C, which calls D, I'd want B, C and D reported as dependencies for A.

like image 351
ninesided Avatar asked Dec 10 '22 22:12

ninesided


1 Answers

On this page, you will find the following query which uses the PUBLIC_DEPENDENCY dictionary table:

 SELECT lvl
     , u.object_id
     , u.object_type
     , LPAD (' ', lvl) || object_name obj
   FROM ( SELECT LEVEL lvl, object_id
            FROM SYS.public_dependency s
         START WITH s.object_id =
                      ( SELECT object_id
                          FROM user_objects
                         WHERE object_name = UPPER ('&OBJECT_NAME')
                           AND object_type = UPPER ('&OBJECT_TYPE'))
         CONNECT BY s.object_id = PRIOR referenced_object_id
         GROUP BY LEVEL, object_id) tree
      , user_objects u
  WHERE tree.object_id = u.object_id
ORDER BY lvl
/
like image 191
Eddie Awad Avatar answered Dec 12 '22 11:12

Eddie Awad