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‘, ‘TRIGGER‘ ,‘JAVA
SOURCE‘, ‘JAVA CLASS‘, ‘‘ )
;
spool off;
set heading on ;
set feedback on ;
set echo on ;
SQL2:
DECLARE
v_objname user_objects.object_name% TYPE ;
v_objtype user_objects.object_type% TYPE ;
CURSOR cur IS
SELECT object_name,
object_type
FROM user_objects
WHERE status
= ‘INVALID‘
AND object_type IN ( ‘FUNCTION‘,
‘JAVA
SOURCE‘ ,
‘JAVA
CLASS‘ ,
‘PROCEDURE‘ ,
‘PACKAGE‘ ,
‘TRIGGER‘ );
BEGIN
OPEN cur;
LOOP
FETCH cur
INTO v_objname,
v_objtype;
EXIT WHEN cur% NOTFOUND;
BEGIN
EXECUTE IMMEDIATE ‘alter
‘ || v_objtype || ‘
‘ || v_objname ||
‘
Compile‘ ;
dbms_output.put_line( ‘编译‘ ||
v_objtype || ‘ ‘ ||
v_objname || ‘()成功‘ );
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( ‘编译‘ ||
v_objtype || ‘ ‘ ||
v_objname ||
‘()失败.‘ || SQLERRM );
END ;
END LOOP ;
CLOSE cur;
END ;