DECLARE
wOwner  VARCHAR2(255) := 'CINEMA';
cScript VARCHAR2(255);
CURSOR  cObjects (pOwner VARCHAR2) is SELECT 'ALTER '||OBJECT_TYPE||' '||OWNER||'.'||OBJECT_NAME||' COMPILE' as COMPILE_COMMAND FROM ALL_OBJECTS WHERE STATUS = 'INVALID' AND OBJECT_TYPE IN ('PACKAGE','FUNCTION','PROCEDURE','TYPE','TRIGGER','VIEW') AND OWNER = 'CINEMA';
BEGIN
    OPEN cObjects(wOwner);
    LOOP
        FETCH cObjects INTO cScript;
        EXIT WHEN cObjects%NOTFOUND;
        
        DBMS_OUTPUT.PUT_LINE(cScript);

        BEGIN
            EXECUTE IMMEDIATE cScript;
        EXCEPTION
            WHEN OTHERS THEN  DBMS_OUTPUT.PUT_LINE('ERRORE ' || cScript);
        END;
        
    END LOOP;
    CLOSE cObjects;
end;
.
r
