Código
SET SERVEROUTPUT ON; DECLARE UnPelicula peliculas%ROWTYPE; resultado INTEGER; resultado2 INTEGER; resultado3 INTEGER; BEGIN FOR UnPelicula IN (SELECT peliculas.codp,peliculas.nombrep, COUNT(DISTINCT alquileres.codc) AS TOTAL FROM socios, peliculas, alquileres WHERE peliculas.codp=alquileres.codp GROUP BY peliculas.codp,peliculas.nombrep ORDER BY TOTAL DESC) LOOP resultado:=UnPelicula.TOTAL; END LOOP; DBMS_OUTPUT.PUT_LINE('****HISTORICO-PRESTAMOS******'); DBMS_OUTPUT.PUT_LINE('****HISTORICO-PRESTAMOS******'); DBMS_OUTPUT.PUT_LINE('****HISTORICO-PRESTAMOS******'); FOR UnPelicula IN (SELECT peliculas.codp,peliculas.nombrep, COUNT(DISTINCT historicoalquileres.codc) AS TOTAL FROM socios, peliculas, historicoalquileres WHERE peliculas.codp=historicoalquileres.codp GROUP BY peliculas.codp,peliculas.nombrep ORDER BY TOTAL DESC) LOOP resultado2:=UnPelicula.TOTAL; resultado3:=resultado+resultado2; DBMS_OUTPUT.PUT_LINE('**********'); DBMS_OUTPUT.PUT_LINE(UnPelicula.nombrep ||' '|| resultado3 || ' Socios Distintos'); DBMS_OUTPUT.PUT_LINE('**********'); END LOOP; END; /