如何判断是否正在使用 PL/SQL 包、过程或函数?

发布于 2024-10-11 19:20:10 字数 77 浏览 12 评论 0原文

如何判断是否正在使用 PL/SQL 包、过程或函数?是否有 Oracle 表或视图包含有关 PL/SQL 包、过程或函数使用情况的统计信息?

How can you tell if a PL/SQL Package, Procedure, or Function is being used? Is there an Oracle table or view that contains statistics on PL/SQL Package, Procedure, or Function usage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

此岸叶落 2024-10-18 19:20:10

您还可以尝试查询 USER/ALL_source:

SELECT * FROM all_source
where UPPER(TEXT) like UPPER('%procedure_name%')

SELECT * FROM all_source
where UPPER(TEXT) like UPPER('%package.function_name%')

您必须忽略自引用,但这应该很容易发现。

您还需要检查 user/all_views 中的“查看”源。不过,请参阅有关查询查看源的其他问题。

您还可以检查包或顶级函数/过程是否与

select * from all_dependencies
where referenced_name like '%PACKAGE_NAME%';

NB 一起使用:根据需要将 user_ 与 all_/dba_ 一起使用,

如果您专门寻找未调用的函数,那么另一种选择是在打开警告的情况下编译代码,然后查找PLW-06002 和 LPW-06006

exec DBMS_WARNING.add_warning_setting_cat('ALL','ENABLE','SESSION')
create or replace function x return number
as
procedure y is begin null; end;
begin
return 0;
return 1;
end;

show errors

Errors for FUNCTION X:

LINE/COL ERROR
-------- -----------------------------------------------------------------
1/1      PLW-05018: unit X omitted optional AUTHID clause; default value DEFINER used
3/1      PLW-06006: uncalled procedure "Y" is removed.
6/1      PLW-06002: Unreachable code

You can also try querying USER/ALL_source:

SELECT * FROM all_source
where UPPER(TEXT) like UPPER('%procedure_name%')

or

SELECT * FROM all_source
where UPPER(TEXT) like UPPER('%package.function_name%')

You'll have to ignore self references, but that should be easy to spot.

You'll also need to check "view" source from user/all_views. See the other question about querying view source though.

you can also check if a package or top level function/procedure is used with

select * from all_dependencies
where referenced_name like '%PACKAGE_NAME%';

NB: switch user_ with all_/dba_ as needed

if you are specifically looking for uncalled functions then another option is to compiler your code with WARNINGS turned on and then look for PLW-06002 and LPW-06006

exec DBMS_WARNING.add_warning_setting_cat('ALL','ENABLE','SESSION')
create or replace function x return number
as
procedure y is begin null; end;
begin
return 0;
return 1;
end;

show errors

Errors for FUNCTION X:

LINE/COL ERROR
-------- -----------------------------------------------------------------
1/1      PLW-05018: unit X omitted optional AUTHID clause; default value DEFINER used
3/1      PLW-06006: uncalled procedure "Y" is removed.
6/1      PLW-06002: Unreachable code
蹲在坟头点根烟 2024-10-18 19:20:10

默认情况下不是。但您可以使用 Oracle 数据库的审核功能。 询问 Tom 是一个关于过程调用审核的长线程!

Not by default. But you can use the audit functionality of your Oracle database. At Ask Tom is a long thread about the auditing of procedure calls!

岁月静好 2024-10-18 19:20:10

如果您使用的是 Oracle 11(R2?),我会给 PL/Scope 一个机会。

该文档指出:PL/Scope 是一个编译器驱动的工具,它在程序单元编译时收集有关 PL/SQL 源代码中标识符的数据,并使其在静态数据字典视图中可用。收集的数据包括有关标识符类型、用法(声明、定义、引用、调用、赋值)以及每个用法在源代码中的位置的信息。

PL/Scope 支持开发强大且有效的 PL /Scope 增加 PL/SQL 的源代码浏览器
通过最大限度地减少浏览和理解源代码的时间来提高开发人员的生产力。

您可以在 http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_plscope.htm#g1010526

If you're on Oracle 11 (R2?), I'd give PL/Scope a chance.

The docu states: PL/Scope is a compiler-driven tool that collects data about identifiers in PL/SQL source code at program-unit compilation time and makes it available in static data dictionary views. The collected data includes information about identifier types, usages (declaration, definition, reference, call, assignment) and the location of each usage in the source code.

PL/Scope enables the development of powerful and effective PL/Scope source code browsers that increase PL/SQL
developer productivity by minimizing time spent browsing and understanding source code.

You can find more about it at http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_plscope.htm#g1010526

∞琼窗梦回ˉ 2024-10-18 19:20:10

您可以通过查询 DBA_DEPENDENCIES 表来查看对象是否具有任何依赖关系。

SELECT OWNER, 
       NAME, 
       TYPE 
  FROM SYS.DBA_DEPENDENCIES 
 WHERE REFERENCED_OWNER = '<your object owner>' 
   AND REFERENCED_NAME = '<your object name>'
   AND REFERENCED_TYPE IN ('PACKAGE', 'PROCEDURE', 'FUNCTION');

此查询将返回存储在 Oracle 实例本身内的代码中的任何依赖项。

它不会透露是否有任何对象在实例外部被调用。

You can see if an object has any dependencies by querying the DBA_DEPENDENCIES table.

SELECT OWNER, 
       NAME, 
       TYPE 
  FROM SYS.DBA_DEPENDENCIES 
 WHERE REFERENCED_OWNER = '<your object owner>' 
   AND REFERENCED_NAME = '<your object name>'
   AND REFERENCED_TYPE IN ('PACKAGE', 'PROCEDURE', 'FUNCTION');

This query will return any dependencies in code stored inside the Oracle instance itself.

It will not reveal whether or not any object is called outside of the instance.

↘人皮目录ツ 2024-10-18 19:20:10

您可以使用像 Toad 这样的编辑器。他们将直接列出您的过程所依赖的对象和引用您的过程的对象。

You can use Editors like Toad. They will directly list both the objects on which your procedure is dependent and objects which reference your procedure.

江城子 2024-10-18 19:20:10

您可能还会发现 pl/sql 工具包 ILO 对您有用正在尝试做。

You might also find the pl/sql instrumentation package ILO useful for what you're trying to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文