CREATE OR REPLACE procedure COMPILE_SCHEMA is
--
-- COMPILE_SCHEMA 7/17/01 R. Tefft
--
-- This procedure compiles all invalid PL/SQL objects in the schema.
-- A common approach is to use a hierarchical query to compile them
-- in order of dependencies, but this can error out if any mutually-dependent
-- objects are found. Instead, we just the blunt-force approach and make
-- 3 passes, re-checking for invalid objects again with each pass.
--
cursor OBJECTS is
select object_name, object_type, status
from USER_OBJECTS
where object_type in ('PACKAGE', 'PACKAGE BODY','VIEW','PROCEDURE','FUNCTION','TRIGGER')
and object_name != 'COMPILE_SCHEMA'
and status = 'INVALID'
order by object_name;
--
cmd varchar2(300);
msg varchar2(2000);
COMPILE_ERROR exception;
pragma EXCEPTION_INIT (COMPILE_ERROR, -24344);
begin
dbms_output.enable(1000000);
--
-- We will make 3 passes, to cover dependencies.
--
for x in 1..3 loop
--
dbms_output.put_line('Pass '||ltrim(to_char(x))||'...');
--
for o in objects loop
if (o.object_type in ('PACKAGE', 'PACKAGE BODY')) then
cmd := 'alter package '||o.object_name||' compile package';
else
cmd := 'alter '||o.object_type||' '||o.object_name||' compile';
end if;
begin
execute immediate cmd;
msg := rpad('Compiled '||lower(o.object_type),25)||o.object_name;
exception
when COMPILE_ERROR then
msg := rpad('Compiled '||lower(o.object_type),25)||rpad(o.object_name,35)||' COMPILE ERROR';
when OTHERS then
msg := rpad('Compiled '||lower(o.object_type),25)||rpad(o.object_name,35)||sqlerrm;
end;
dbms_output.put_line(rtrim(msg));
end loop;
end loop;
end COMPILE_SCHEMA;
/