使用PL/Scope分析PL/SQL代码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用PL/Scope分析PL/SQL代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4587字,纯文字阅读大概需要7分钟。
内容图文
从11g开始Oracle引入了PL/Scope 用于编译器收集PL/SQL程序单元的所有标识符(变量名、常量名、程序名等)。 收集到的信息可通过一
使用PL/Scope分析你的PL/SQL代码
从11g开始Oracle引入了PL/Scope 用于编译器收集PL/SQL程序单元的所有标识符(变量名、常量名、程序名等)。
收集到的信息可通过一系列静态数据字典视图获取。
可帮助我们了解标识符的声明,定义,,引用,调用或赋值以及所在源代码的位置。
使用PL/Scope, 开发者可以执行复杂的代码分析。
1、启用 Enabling PL/Scope
plscope_settings='IDENTIFIERS:ALL' /plscope_settings 参数有2个可选值:
IDENTIFIERS:ALL or IDENTIFIERS:NONE(默认不收集)
2、关于视图 ALL_IDENTIFIERS View
当1中参数设置为IDENTIFIERS:ALL,同时在同一会话中编译程序单元后,该单元所有标识符信息被收集到视图ALL_IDENTIFIERS中。
以下是该视图字段简介:
【OWNER】 The owner of the program unit containing the identifier
【NAME】 The name of the identifier
【TYPE】 The type of the identifier, such as FORALL OUT (an out argument), CONSTANT, PACKAGE, or RECORD
【SIGNATURE】 签名,用于区分同名标识符的唯一字符串;
A unique string for each distinct identifier, across all program units, useful for distinguishing between different identifiers that happen to have the same name
【OBJECT_NAME】 The name of the program unit containing the identifier OBJECT_TYPE The type of the program unit containing the identifier, such as PACKAGE, TRIGGER, or PROCEDURE
【USAGE】 针对标识符的操作类型 The type of usage of the identifier (such as a declaration or an assignment)
【USAGE_ID】 A sequentially generated integer value for an identifier, unique within its program unit
【USAGE_CONTEXT_ID】A foreign key reflexive back to USAGE_ID; in essence, the parent of this identifier appearance (for example, the context of a variable’s declaration is the name of the subprogram in which the variable is declared)
【LINE】 标识符出现的行 The number of the line on which the identifier appears
【COL】 标识符出现的列 The column position in the line at which the identifier appears
你可以获取给定程序单元的所有标识符信息:
SELECT * FROM all_identifiers ai WHERE ai.owner = USER line3、PL/Scope追踪的标识符用法 Usages Tracked by PL/Scope
ASSIGNMENT: 赋值操作。包括:=,FETCH.. INTO以及OUT 、IN OUT模式参数。
CALL:调用操作。
DECLARATION: 声明。Indicates that the identifier is declared.
REFERENCE: 引用。Indicates that an identifier is used in the program without a change in its value. Examples include raising an exception, passing the identifier to an IN or IN OUT mode parameter of a subprogram or USING clause of EXECUTE IMMEDIATE, and using the identifier in a %TYPE declaration.
DEFINITION:定义。Tells the compiler how to implement or use a previously declared identifier. The following identifier types will have a DEFINITION row in ALL_IDENTIFIERS: FUNCTION, OBJECT, PACKAGE, PROCEDURE, TRIGGER, and EXCEPTION.
这些用法便于更加容易获取关于程序单元的详细信息。
如果我想看看程序单元中的变量的声明部分:
4、理解标识符的层级关系 Using Usage IDs to Understand Identifier Hierarchy
一个包可以包含一个或多个子程序;一个子程序可以有一个或多个参数。你可以使用PL/Scope探索这种层级关系。
例如:
You can then execute a hierarchical query, specifying the usage_context_id column as the parent of a row in the ALL_IDENTIFIERS view, to see the hierarchy of identifiers shown in Listing 2.
你可以执行一个层级查询,指定usage_context_id作为父级行:
Code Listing 2: Querying against ALL_IDENTIFIERS view to see the hierarchy of identifiers WITH plscope_hierarchy AS (SELECT line , col , name , TYPE , usage , usage_id , usage_context_id FROM all_identifiers WHERE owner = USER AND object_name = 'PLSCOPE_DEMO' AND object_type = 'PACKAGE BODY') SELECT LPAD ('-', 3 * (LEVEL - 1)) || TYPE || ' ' || name || ' (' || usage || ')' identifier_hierarchy FROM plscope_hierarchy START WITH usage_context_id = 0 CONNECT BY PRIOR usage_id = usage_context_id ORDER SIBLINGS BY line, col PACKAGE PLSCOPE_DEMO (DEFINITION) ) ) ) ) )内容总结
以上是互联网集市为您收集整理的使用PL/Scope分析PL/SQL代码全部内容,希望文章能够帮你解决使用PL/Scope分析PL/SQL代码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。