For loop cursor(implicit Cursor)
and open..fetch(explicit cursor)
cursor works differently. When using implicit cursor opening and closing of cursor is automatically taken care of.From implementation stand point it is easier to implement when compared to explicit cursor.From performance standpoint they are faster as well.
Bonus – you can use the fields in the select statement as cursor variables and there isn’t any need to declare variables to fetch the records to.
Not sure of the purpose of multiple loops, i have removed redundant code and simplified.This should work.
SET SERVEROUTPUT ON SIZE 100000
DECLARE
BEGIN
FOR rec IN (SELECT IDPLEDGE, PLEDGEAMT, PAYMONTHS, PLEDGEDATE, PLEDGEAMT*PAYMONTHS TOTPLEDGEAMT, FIRSTPLEDGE
FROM DD_PLEDGE
ORDER BY IDPLEDGE, PLEDGEDATE)
LOOP
DBMS_OUTPUT.PUT_LINE('pledge ID: ' || rec.IDPLEDGE);
DBMS_OUTPUT.PUT_LINE('pledge amount: ' || rec.PLEDGEAMT);
DBMS_OUTPUT.PUT_LINE('number of monthly payments: ' || rec.PAYMONTHS);
DBMS_OUTPUT.PUT_LINE('payment date: ' || rec.PLEDGEDATE);
DBMS_OUTPUT.PUT_LINE('payment amount: ' || rec.TOTPLEDGEAMT);
DBMS_OUTPUT.PUT_LINE('first payment: ' || rec.FIRSTPLEDGE);
END LOOP;
END;
CLICK HERE to find out more related problems solutions.