龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 数据库类 > Oracle 技术 >

在Oracle中重编译所有无效的存储过程

时间:2011-04-12 23:18来源:未知 作者:admin 点击:
分享到:
SQL_PLUS中, spool ExecCompProc.sql select 'alter procedure '||object_name||' compile; ' From all_objects where status = 'INVALID' and object_type = 'PROCEDURE'; spool off @ExecCompProc.Sql; 整理成一个存储过程 Create Or Replace P

SQL_PLUS中,

spool ExecCompProc.sql
select 'alter procedure '||object_name||' compile;

' From all_objects where status = 'INVALID' and object_type = 'PROCEDURE';
spool off

@ExecCompProc.Sql; 

整理成一个存储过程

Create Or Replace Procedure Zl_Compile_Invalid_Procedure As
Strsql Varchar2(200);
Begin
For x In (Select Object_Name From All_Objects Where Status = 'INVALID'

And Object_Type = 'PROCEDURE') Loop
Strsql := 'Alter Procedure ' || x.Object_Name || ' Compile';
Begin
  Execute Immediate Strsql;
  Exception
--When Others Then Null;     
When OTHERS Then dbms_output.put_line(Sqlerrm);     
End;
End Loop;
End;

执行

exec Zl_Compile_Invalid_Procedure;

如果要看到无法重编译的过程的出错信息,需要执行前设置set serverout on

(责任编辑 火凤凰 sunsj@51cto.com  TEL:(010)68476636-8007)


精彩图集

赞助商链接