Pruebalo así:
Código SQL:
Ver originalCREATE OR REPLACE
PROCEDURE "DesbalanceDiarioPrueba" IS
CURSOR PRUEBA IS
rango1 DATE;
rango2 DATE;
CURSOR DDS IS
SELECT SUM(NUMLLA) LLAM ,SUM(ICMINO) MINS, ICOPAC,'Saliente' tipo FROM ICRESDIA
WHERE ICDATE BETWEEN rango1 AND rango2
AND ICACAS IN (169,170,98,99,100,4,5,81,87,28,29,34,35,32,33,43,44,94,95,97,60)--193
GROUP BY icopac;
CURSOR OPES IS
SELECT 'Tipo' Tipo, DESOPE, SUM(llasal) lls, SUM(minsal) MS
FROM ICDESRES
WHERE DESDIA BETWEEN rango1 AND rango2
AND ictipe IN ('C','N','R')
GROUP BY DESOPE
ORDER BY desope;
BEGIN
SELECT TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE,-1)+1))
INTO rango1
FROM dual;
SELECT TRUNC(sysdate-1)
INTO rango2
FROM dual;
FOR r_OPES IN OPES LOOP
--DBMS_OUTPUT.PUT_LINE(r_OPES.Tipo||','||r_OPES.DESOPE||','||r_OPES.lls||','||r_OPES.MS);
FOR r_DDS IN DDS LOOP
IF r_OPES.DESOPE=r_DDS.ICOPAC THEN
DBMS_OUTPUT.PUT_LINE(r_OPES.Tipo||','||r_DDS.tipo||','||r_DDS.ICOPAC||','||r_DDS.LLAM-r_OPES.lls||','||r_DDS.MINS-r_OPES.MS);
END IF;
END LOOP;
END LOOP;
END;
Nos cuentas