设为首页 加入收藏

TOP

PL/SQL相关的数据字典(一)
2015-07-26 15:02:50 来源: 作者: 【 】 浏览:115
Tags:PL/SQL 相关 数据 字典

有时候,我们在PL/SQL开发过程中会遇到以下问题:
1)我的程序到底依赖于哪些数据库对象?
2)哪个包中调用了一个其他包中的子程序或变量?
3)我的哪个子程序的参数使用了不合适的数据类型?
4)我的所有子程序是否都使用了适当的优化级别?


傻一点的做法是到代码里搜。。。
聪明的人会使用以下数据字典视图:


1、数据字典基础
数据字典是由多个实例创建的表和视图组成,用户通常只有对数据字典查询权限。
绝大多数的数据字段有三个版本组成:
1)用户视图,USER_开头,包含当前已登录用户拥有的数据库对象信息。
2)全部视图,ALL_开头,包含当前已登录用户已读取的数据库对象信息。
3)管理员视图,DBA_开头,这类视图包含一个实例中所有数据库对象信息,普通用户通常无权访问。


例如:
SELECT * FROM user_objects; –我拥有的所有数据库对象信息
SELECT * FROM all_objects; –我有权读取的数据库对象信息
SELECT * FROM dba_objects; –管理员可访问的整个数据库的对象信息


2、显示存储对象的信息 USER_OBJECTS
包含列介绍(英文太简单不翻译了):
OBJECT_NAME: Name of the object


OBJECT_TYPE: Type of the object, such as PACKAGE, FUNCTION, or TRIGGER


STATUS: Status of the object—VALID or INVALID


LAST_DDL_TIME: Time stamp indicating the last time this object was changed


来看几个例子:


1)显示我模式下所有表:


2)显示所有失效的对象名:


3)显示所有今天修改的对象:


3、搜索和展现源代码 USER_SOURCE
列介绍:
NAME: Name of the object


TYPE: Type of the object (ranging from PL/SQL program units to Java source and trigger source)


LINE: Number of the line of the source code


TEXT: Text of the source code


例如: 我需要改变包SALES_MGR中CALC_TOTALS过程的参数列表。我想找到哪些地方对该过程进行了调用。


当然,这个查询可能连注释也查出来,还有就是不符合LIKE格式的字符串将无法检索出来,例如:
SALES_MGR.
CALC_TOTALS


那么假设,我们的代码都是比较标准的,这个查询还是做了一个不错的工作。
另外,对于11g而言,你可以使用PL/Scope特性。


4、存储代码的编译设置 USER_PLSQL_OBJECT_SETTINGS
PLSQL_OPTIMIZE_LEVEL: 编译对象的优化级别


PLSQL_CODE_TYPE: 对象的编译模式


PLSQL_DEBUG: Whether or not the object was compiled for debugging 对象是否为调试而编译


PLSQL_WARNINGS: 编译对象的编译警告设置


NLS_LENGTH_SEMANTICS: NLS length semantics that were used to compile the object 编译对象的语义长度设置


找出所有没有采用有效编译时优化的程序单元:


SELECT name
FROM user_plsql_object_settings
WHERE plsql_optimize_level < 2


0级表示未采取任何优化。1表示最低限度的优化。2者都不应该存在于生产环境。


找出那些禁用了编译时警告的程序。


5、关于过程和函数的详细信息 USER_PROCEDURES
AUTHID: Shows whether a procedure or a function is defined as an invoker rights (CURRENT_USER) or definer rights (DEFINER) program unit 调用者权限或是定义者权限


DETERMINISTIC: Set to YES if the function is defined to be deterministic, which theoretically means that the value returned by the function is determined completely by the function’s argument values 是否确定性


PIPELINED: Set to YES if the function is defined as a pipelined function, which means that it can be executed in parallel as part of a parallel query 是否管道函数


OVERLOAD: Set to a positive number if this subprogram is overloaded, which means that there are at least two subprograms with this name in the same package 是否重载


找出所有运行在调用者权限下的过程和函数


显示所有声明为确定性的函数:


6、分析和修改触发器状态 USER_TRIGGERS
TRIGGER_NAME: The name of the trigger


TRIGGER_TYPE: A string that shows if this is a BEFORE or AFTER trigger and whether it is a row- or statement-level trigger (in a trigger that is fired before an INSERT statement, for example, the value of this column is BEFORE STATEMENT)


TRIGGERING_EVENT: The type of SQL operation—such as INSERT, INSERT OR UPDATE, DELETE OR UPDATE—that will cause the trigger to fire


TABLE_NAME: The name of the table on which the trigger is defined


STATUS: The status of the trigger—ENABLED or DISABLED


WHEN_CLAUSE: An optional clause you can use to avoid unnecessary execution of the trigger body


TRIGGER_BODY: The code executed when the trigger fires


找出所有已禁用的触发器:


找出所有定义在EMPLOYEES表上的行级触发器:


Find all triggers that fire when an UPDATE operation is performed:
找出所有包含update操作触发的触发器


7、对象依赖分析 USER_DEPENDENCIES
NAME: Name of the object


TYPE: Type of the object


REFERENCED_OWNER: Owner of the referenced object 被引用对象的所有者


REFERENCED_NAME: Name of the referenced object 被引用对象的名称


REFERENCED_TYPE: Type

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Oracle 12c中增强的PL/SQL功能 下一篇Oracle update和order by

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: