oracle decode_分享6个实用脚本--一键编译Oracle数据库失效对象

概述

Oracle数据库有时候会发现存在一些失效对象,特别是做迁移之类,如果失效对象比较多一个一个编译也是很麻烦,那么有没脚本可以把相关的失效对象一次性编译呢?


1、compile_all_bodies.sql

Description : Compiles all invalid package bodies for specified schema, or all schema.

SET PAGESIZE 0SET FEEDBACK OFFSET VERIFY OFF​SPOOL temp.sql​SELECT 'ALTER PACKAGE ' || a.owner || '.' || a.object_name || ' COMPILE BODY;'FROM all_objects aWHERE a.object_type = 'PACKAGE BODY'AND a.status = 'INVALID'AND a.owner = Decode(Upper('&&1'), 'ALL',a.owner, Upper('&&1'));​SPOOL OFF​-- Comment out following line to prevent immediate run@temp.sql​SET PAGESIZE 14SET FEEDBACK ONSET VERIFY ON
df050dfedb9c50c64c0efceb2750a515.png

2、compile_all_funcs.sql

Description : Compiles all invalid functions for specified schema, or all schema.

SET PAGESIZE 0SET FEEDBACK OFFSET VERIFY OFF​SPOOL temp.sql​SELECT 'ALTER FUNCTION ' || a.owner || '.' || a.object_name || ' COMPILE;'FROM all_objects aWHERE a.object_type = 'FUNCTION'AND a.status = 'INVALID'AND a.owner = Decode(Upper('&&1'), 'ALL',a.owner, Upper('&&1'));​SPOOL OFF​-- Comment out following line to prevent immediate run@temp.sql​SET PAGESIZE 14SET FEEDBACK ONSET VERIFY ON
04735e8faa48892b03e76d44e0ec0144.png

3、compile_all_procs.sql

Description : Compiles all invalid procedures for specified schema, or all schema

SET PAGESIZE 0SET FEEDBACK OFFSET VERIFY OFF​SPOOL temp.sql​SELECT 'ALTER PROCEDURE ' || a.owner || '.' || a.object_name || ' COMPILE;'FROM all_objects aWHERE a.object_type = 'PROCEDURE'AND a.status = 'INVALID'AND a.owner = Decode(Upper('&&1'), 'ALL',a.owner, Upper('&&1'));​SPOOL OFF​-- Comment out following line to prevent immediate run@temp.sql​SET PAGESIZE 14SET FEEDBACK ONSET VERIFY ON
c8f836360ab9055223ba22a2ad976e3b.png

4、compile_all_specs.sql

Description : Compiles all invalid package specifications for specified schema, or all schema.

SET PAGESIZE 0SET FEEDBACK OFFSET VERIFY OFF​SPOOL temp.sql​SELECT 'ALTER PACKAGE ' || a.owner || '.' || a.object_name || ' COMPILE;'FROM all_objects aWHERE a.object_type = 'PACKAGE'AND a.status = 'INVALID'AND a.owner = Decode(Upper('&&1'), 'ALL',a.owner, Upper('&&1'));​SPOOL OFF​-- Comment out following line to prevent immediate run@temp.sql​SET PAGESIZE 14SET FEEDBACK ONSET VERIFY ON
b54ea113abccaec0969f035af3ac505b.png

5、compile_all_trigs.sql

Description : Compiles all invalid triggers for specified schema, or all schema.

SET PAGESIZE 0SET FEEDBACK OFFSET VERIFY OFF​SPOOL temp.sql​SELECT 'ALTER TRIGGER ' || a.owner || '.' || a.object_name || ' COMPILE;'FROM all_objects aWHERE a.object_type = 'TRIGGER'AND a.status = 'INVALID'AND a.owner = Decode(Upper('&&1'), 'ALL',a.owner, Upper('&&1'));​SPOOL OFF​-- Comment out following line to prevent immediate run@temp.sql​SET PAGESIZE 14SET FEEDBACK ONSET VERIFY ON
b2ed7b940d9a46be9cf87d3274ce6779.png

6、compile_all_views.sql

Description : Compiles all invalid views for specified schema, or all schema.

SET PAGESIZE 0SET FEEDBACK OFFSET VERIFY OFF​SPOOL temp.sql​SELECT 'ALTER VIEW ' || a.owner || '.' || a.object_name || ' COMPILE;'FROM all_objects aWHERE a.object_type = 'VIEW'AND a.status = 'INVALID'AND a.owner = Decode(Upper('&&1'), 'ALL',a.owner, Upper('&&1'));​SPOOL OFF​-- Comment out following line to prevent immediate run@temp.sql​SET PAGESIZE 14SET FEEDBACK ONSET VERIFY ON
dfb557522c8ea178ed6c6fbf0865878e.png

觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~

1e2cc637a645e1e43596b26bde276cac.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值