假设我有一个包含my_procage的包my_package。
我想知道正在使用/调用哪个other_procedures(在其他一些包中)(例如来自my_other_package.my_other_procedure)
这一切都可能吗?如果可能,怎么样?
我可以使用ALL_DEPENDENCIES
,但ALL_DEPENDENCIES
的问题在于它为我提供了一般使用my_package
的对象列表,而不是my_procedure
。 my_package
有大约50个奇怪的功能和程序,ALL_DEPENDENCIES
对my_package
包的查询给了我30个奇怪的结果。
我的数据库架构很庞大,查询ALL_SOURCES需要很长时间。
以下查询在下面的答案的帮助下构建,似乎运作良好:
select /*+ parallel(als, 16) */ * from all_source als
where type in ('PROCEDURE','PACKAGE BODY')
and name in ( select NAME from all_Dependencies where referenced_name = 'OE_HEADER_UTIL')
and upper(text) like '%INSERT_ROW%';
答案 0 :(得分:2)
尝试使用视图ALL_SOURCE
,它包含所有存储过程的源代码,更好的是ALL_DEPENDENCIES
。
答案 1 :(得分:1)
我的解决方案(有点复杂,但适用于我的包):
SET SERVEROUTPUT ON
DECLARE
l_own VARCHAR2 (30) := 'YOUR_OWNER'; -- package owner
l_obj VARCHAR2 (30) := 'YOUR_PACKAGE'; -- package name
l_priv VARCHAR2 (30);
l_cnt NUMBER := 0;
BEGIN
DBMS_OUTPUT.put_line ('Checking required privileges for [' || l_own || '.' || l_obj || ']');
DBMS_OUTPUT.put_line ('TABLES and VIEWS');
SELECT MAX (line)
INTO l_cnt
FROM all_source
WHERE owner = l_own AND name = l_obj AND TYPE = 'PACKAGE BODY';
IF l_cnt = 0 THEN
DBMS_OUTPUT.put_line (
'ERROR - Cannot read the [' || l_own || '.' || l_obj || '] package sources!');
RETURN;
END IF;
FOR x IN (WITH txt AS
(SELECT line, UPPER (text) text, 'FROM\s*([_|\$|[:upper:]]+)' regexp
FROM all_source
WHERE owner = l_own AND name = l_obj AND REGEXP_INSTR (text, 'FROM\s*') > 0),
tabs AS
(SELECT line, text, tab
FROM ( SELECT line,
text,
REGEXP_REPLACE (REGEXP_REPLACE (REGEXP_SUBSTR (text,
regexp,
1,
LEVEL),
'^FROM\s*'),
'^V\$',
'V_$')
tab
FROM txt
CONNECT BY REGEXP_SUBSTR (text,
regexp,
1,
LEVEL)
IS NOT NULL)
WHERE tab IS NOT NULL AND NOT REGEXP_LIKE (tab, 'DUAL|TABLE')),
syns AS
(SELECT line,
text,
tab,
table_owner syn_own,
NVL (table_name, tab) syn_obj
FROM tabs INNER JOIN all_synonyms ON synonym_name(+) = tabs.tab),
syns_objs AS
(SELECT object_type typ, NVL (syn_own, owner) own, syn_obj obj
FROM syns INNER JOIN dba_objects ON syns.syn_obj = object_name)
SELECT DISTINCT typ, own, obj
FROM syns_objs
WHERE typ <> 'SYNONYM'
ORDER BY typ, own, obj) LOOP
BEGIN
SELECT DISTINCT privilege
INTO l_priv
FROM dba_tab_privs
WHERE table_name = x.obj AND owner = x.own;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
DBMS_OUTPUT.put_line (
RPAD ('. [' || x.typ || ']:' || x.own || '.' || x.obj, 80, ' ')||
NVL (l_priv, 'NO_PRIVILEGE'));
END LOOP;
DBMS_OUTPUT.put_line ('PACKAGES');
FOR x
IN ( SELECT lvl,
object_type typ,
owner own,
object_name obj
FROM ( SELECT LEVEL lvl, object_id
FROM public_dependency s
START WITH s.object_id =
(SELECT object_id
FROM all_objects
WHERE owner = l_own
AND object_name = l_obj
AND object_type = 'PACKAGE BODY')
CONNECT BY s.object_id = PRIOR referenced_object_id
GROUP BY LEVEL, object_id) tree,
all_objects u
WHERE tree.object_id = u.object_id AND u.owner <> 'PUBLIC'
ORDER BY lvl) LOOP
BEGIN
SELECT DISTINCT privilege
INTO l_priv
FROM dba_tab_privs
WHERE table_name = x.obj AND owner = x.own;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
END;
DBMS_OUTPUT.put_line (
RPAD (LPAD ('.', x.lvl, '.') || '[' || x.typ || ']:' || x.own || '.' || x.obj, 80, ' ')||
NVL (l_priv, 'NO_PRIVILEGE'));
END LOOP;
END;
/