Script to compile invalid objects in DB

来源:互联网 发布:mysql安全配置 编辑:程序博客网 时间:2024/06/04 19:27


REM: Script to compile invalid objects in DB after refreshingREM:REM:*****************************************REM:REM: NOTE: PLEASE TEST THIS SCRIPT BEFORE USE.REM: Author will not be responsible for any damage that may be cause by this script.REM:*****************************************set pagesize 0set feedback offset trimspool onpromptprompt Run the script as sysdba otherwise invalid objects will remain (ORA-01031 error)promptprompt Run the script several times. It only takes long the first timepromptprompt check the progress of compilation by issueing from another sessionprompt select count(*) "invalid" from dba_objects where status <> 'VALID';promptprompt hit <enter> to continuepausespool compile.lisselect 'alter '||object_type||' '||owner||'.\"'||object_name||'\" compile;'from dba_objectswhere status<>'VALID'and object_type not in ('PACKAGE BODY','TYPE BODY','UNDEFINED','JAVA CLASS','SYNONYM')unionselect 'alter package '||owner||'.'||object_name||' compile body;'from dba_objectswhere status<>'VALID'and object_type='PACKAGE BODY'unionselect 'alter type '||owner||'.'||object_name||' compile body;'from dba_objectswhere status<>'VALID'and object_type='TYPE BODY'unionselect 'alter materialized view '||owner||'.'||object_name||' compile;'from dba_objectswhere status<>'VALID'and object_type='UNDEFINED'unionselect 'alter java class '||owner||'.\"'||object_name||'\" resolve;'from dba_objectswhere status<>'VALID'and object_type='JAVA CLASS'unionselect 'alter synonym '||owner||'.'||object_name||' compile;'from dba_objectswhere status<>'VALID'and object_type='SYNONYM'and owner<>'PUBLIC'unionselect 'alter public synonym '||object_name||' compile;'from dba_objectswhere status<>'VALID'and object_type='SYNONYM'and owner='PUBLIC';spool offset feedback on