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

前端 未结 4 510
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 21:59

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

相关标签:
4条回答
  • 2021-01-19 22:30

    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
    /
    
    0 讨论(0)
  • 2021-01-19 22:32

    I agree with EddieAwad.

    Its valuable to point out that Oracle only tracks the dependencies down to the object level. If you have your stored procedures in a package you can only track the dependencies if the package, not the individual functions/procedures within the package.

    If you're looking to track intra-package dependencies then you'll need a PLSQL parser.

    0 讨论(0)
  • 2021-01-19 22:32

    To get all details:

    select * from all_dependencies where owner = '&OWNER' and NAME='&OBJECT_NAME' 
    
    0 讨论(0)
  • 2021-01-19 22:38

    Something else worth pointing out here, is that there are certain cases where the dependency may only be at runtime, which unfortunately will not show up in the metadata.

    For example, if you are constructing a SQL statement at runtime, you may have code similar to:

    ...
    mysql := 'select count(*) from '||table_name_in;
    execute immediate mysql;
    ...
    

    I've been burnt by this a few times, but there's unfortunately no way to find these types of dependencies in advance since it potentially depends on user input.

    0 讨论(0)
提交回复
热议问题