Recompiling invalid Oracle objects

本文介绍了一种使用SQL*Plus脚本查找并重新编译Oracle数据库中无效对象的方法。该脚本能够搜索Oracle数据字典中的无效对象,并创建一个包含这些对象名称的文件,随后调用另一个脚本进行重新编译。此过程对于确保数据库迁移后所有对象的有效性和可执行性至关重要。
Recompiling invalid Oracle objects
Whenever an oracle object is marked as invalided because of a table, that has been changed, the Oracle professional can change the object to valid by using a SQL*Plus script. This script will search the Oracle data dictionary for invalid objects, create a spool file with the names of the invalid objects, than invoke a script to re-compile all of these invalid objects. The following script should be used whenever a change is made to an Oracle table or index, since the DBA must ensure that all object are valid and executable.
In Oracle8i, we now have a supported script to perform this function of re-compiling invalid objects. The utility is called Recompile PL/SQL, or RP for short. The script is called utlrp.sql and is located in the $ORACLE_HOME/rdbms/admin/ directory. However, most experienced Oracle DBAs prefer a home-made script for this purpose.
Although invalid PL/SQL modules get automatically recompiled on use, it is useful to run this script ahead of time (e.g. as one of the last steps in your migration), since this will either eliminate or minimize subsequent latencies caused due to on-demand automatic recompilation at runtime.
Oracle highly recommends running this script towards the end of of any migration/upgrade/downgrade.
Set heading off;
set feedback off;
set echo off;
Set lines 999;
 
Spool run_invalid.sql
 
select
   'ALTER ' || OBJECT_TYPE || ' ' ||
   OWNER || '.' || OBJECT_NAME || ' COMPILE;'
from
   dba_objects
where
   status = 'INVALID'
and
   object_type in ('PACKAGE','FUNCTION','PROCEDURE')
;
 
spool off;
 
set heading on;
set feedback on;
set echo on;
 
@run_invalid.sql
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值