暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle编译无效对象

dblife 2019-12-30
429

元旦快乐


通过DBA_OBJECTS数据字典查找无效对象,并重新编译

复制以下内容,编辑为脚本compile.sql,以sys账号执行

SQL>@compile.sql

REM --------------------------------------------------------------------------
REM
REM compile.sql - Recompiles All Invalid Database Objects
REM
REM This SQL script selects all INVALID database objects from DBA_OBJECTS and
REM attempts to recompile them. It then selects all remaining INVALID database
REM objects to see how many did not compile successfully.
REM
REM --------------------------------------------------------------------------

REM Set the environment variables

set echo off
set feedback off
set pages 0
set lines 100

prompt
prompt ************************************************
prompt Selecting all INVALID objects in the database...
prompt ************************************************
prompt

REM Start spooling the results into a temporary file

spool temp.sql

REM This select statement will generate a list of all invalid database objects

SELECT 'ALTER ' || OBJECT_TYPE || ' ' ||
OWNER || '.' || OBJECT_NAME || ' COMPILE;'
FROM DBA_OBJECTS
WHERE STATUS = 'INVALID' AND
OBJECT_TYPE NOT IN ('PACKAGE BODY', 'TYPE BODY');

spool off;

prompt
prompt
prompt ****************************
prompt Compiling INVALID objects...
prompt ****************************
prompt

REM Run the spool file as a series of 'ALTER... COMPILE;' statements

@temp.sql

REM Remove the temporary spool file

host erase temp.sql

prompt
prompt ****************************************
prompt Compilation of INVALID objects complete.
prompt ****************************************
prompt
prompt
prompt **********************************************************
prompt Selecting all remaining INVALID objects in the database...
prompt **********************************************************
prompt

SELECT 'ALTER ' || OBJECT_TYPE || ' ' ||
OWNER || '.' || OBJECT_NAME || ' COMPILE;'
FROM DBA_OBJECTS
WHERE STATUS = 'INVALID' AND
OBJECT_TYPE NOT IN ('PACKAGE BODY', 'TYPE BODY');

prompt

REM End of script  

复制


参考:Example: How to Recompile all Invalid Database Objects (SCR 209) (Doc ID 125780.1)



文章转载自dblife,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论