BEGIN
FOR cur IN
(
SELECT OBJECT_NAME,
OBJECT_TYPE ,
owner
FROM all_objects
WHERE object_type IN('PACKAGE', 'PACKAGE BODY')
AND owner = ':OWNER
AND status = 'INVALID'
)
LOOP
BEGIN
IF cur.OBJECT_TYPE = 'PACKAGE BODY' THEN
EXECUTE IMMEDIATE 'alter package "' || cur.owner || '"."' || cur.OBJECT_NAME ||
'" compile body';
ELSE
EXECUTE IMMEDIATE 'alter ' || cur.OBJECT_TYPE || ' "' || cur.owner || '"."' ||
cur.OBJECT_NAME || '" compile';
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Errors compiling - ' || cur.owner ||'.'||cur.object_name);
END;
END LOOP;
END;