I am trying to display pledge ID, pledge amount, number of monthly payments, payment date, payment amount, and first payment made for each pledge, sorted by pledge ID and then by payment date.
Name Null? Type
----------- -------- -----------
IDPLEDGE NOT NULL NUMBER(5)
IDDONOR NUMBER(4)
PLEDGEDATE DATE
PLEDGEAMT NUMBER(8,2)
IDPROJ NUMBER(5)
IDSTATUS NUMBER(2)
WRITEOFF NUMBER(8,2)
PAYMONTHS NUMBER(3)
CAMPAIGN NUMBER(4)
FIRSTPLEDGE CHAR(1)
Here is my code:
DECLARE
lv_pledge_ID DD_PLEDGE.IDPLEDGE%TYPE;
lv_pledge_amount DD_PLEDGE.PLEDGEAMT%TYPE;
lv_num_month_pay DD_PLEDGE.PAYMONTHS%TYPE;
lv_pay_date DATE;
lv_pay_amount NUMBER(6);
lv_frst_pledge DD_PLEDGE.FIRSTPLEDGE%TYPE;
BEGIN
FOR rec IN (SELECT DISTINCT IDDONOR FROM DD_PLEDGE)
LOOP
SELECT IDPLEDGE, PLEDGEAMT, PAYMONTHS, PLEDGEDATE, PLEDGEAMT*PAYMONTHS, FIRSTPLEDGE
INTO lv_pledge_ID, lv_pledge_amount, lv_num_month_pay, lv_pay_date, lv_pay_amount, lv_frst_pledge
FROM DD_PLEDGE
ORDER BY IDPLEDGE, PLEDGEDATE;
LOOP
DBMS_OUTPUT.PUT_LINE('pledge ID: ' || rec.lv_pledge_ID);
DBMS_OUTPUT.PUT_LINE('pledge amount: ' || rec.lv_pledge_amount);
DBMS_OUTPUT.PUT_LINE('number of monthly payments: ' || rec.lv_num_month_pay);
DBMS_OUTPUT.PUT_LINE('payment date: ' || rec.lv_pay_date);
DBMS_OUTPUT.PUT_LINE('payment amount: ' || rec.lv_pay_amount);
DBMS_OUTPUT.PUT_LINE('first payment: ' || rec.lv_frst_pledge);
END LOOP;
END LOOP;
END;
I get an error:
Error report -
ORA-06550: line 16, column 46:
PLS-00302: component 'LV_PLEDGE_ID' must be declared
ORA-06550: line 16, column 4:
PL/SQL: Statement ignored
ORA-06550: line 17, column 50:
PLS-00302: component 'LV_PLEDGE_AMOUNT' must be declared
ORA-06550: line 17, column 4:
PL/SQL: Statement ignored
ORA-06550: line 18, column 63:
PLS-00302: component 'LV_NUM_MONTH_PAY' must be declared
ORA-06550: line 18, column 4:
PL/SQL: Statement ignored
ORA-06550: line 19, column 49:
PLS-00302: component 'LV_PAY_DATE' must be declared
ORA-06550: line 19, column 4:
PL/SQL: Statement ignored
ORA-06550: line 20, column 51:
PLS-00302: component 'LV_PAY_AMOUNT' must be declared
ORA-06550: line 20, column 4:
PL/SQL: Statement ignored
ORA-06550: line 21, column 50:
PLS-00302: component 'LV_FRST_PLEDGE' must be declared
ORA-06550: line 21, column 4:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
The error message doesn't make any sense to me. Why doesn't it recognize my variables?
Updated:
BEGIN
FOR rec IN (SELECT DISTINCT IDDONOR FROM DD_PLEDGE)
LOOP
SELECT IDPLEDGE, PLEDGEAMT, PAYMONTHS, PLEDGEDATE, PLEDGEAMT*PAYMONTHS AS PAYAMONT, 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.PAYAMONT);
DBMS_OUTPUT.PUT_LINE('first payment: ' || rec.FIRSTPLEDGE);
END LOOP;
END LOOP;
END;
The error:
Error report -
ORA-06550: line 16, column 3:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
; <an identifier> <a double-quoted delimited-identifier>
The symbol ";" was substituted for "end-of-file" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Update: Deleted the second LOOP.
BEGIN
FOR rec IN (SELECT DISTINCT IDDONOR FROM DD_PLEDGE)
LOOP
SELECT IDPLEDGE, PLEDGEAMT, PAYMONTHS, PLEDGEDATE, PLEDGEAMT*PAYMONTHS AS PAYAMONT, FIRSTPLEDGE
FROM DD_PLEDGE
ORDER BY IDPLEDGE, PLEDGEDATE;
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.PAYAMONT);
DBMS_OUTPUT.PUT_LINE('first payment: ' || rec.FIRSTPLEDGE);
END LOOP;
END;
The error:
Error report -
ORA-06550: line 4, column 3:
PLS-00428: an INTO clause is expected in this SELECT statement
ORA-06550: line 7, column 48:
PLS-00302: component 'IDPLEDGE' must be declared
ORA-06550: line 7, column 4:
PL/SQL: Statement ignored
ORA-06550: line 8, column 52:
PLS-00302: component 'PLEDGEAMT' must be declared
ORA-06550: line 8, column 4:
PL/SQL: Statement ignored
ORA-06550: line 9, column 65:
PLS-00302: component 'PAYMONTHS' must be declared
ORA-06550: line 9, column 4:
PL/SQL: Statement ignored
ORA-06550: line 10, column 51:
PLS-00302: component 'PLEDGEDATE' must be declared
ORA-06550: line 10, column 4:
PL/SQL: Statement ignored
ORA-06550: line 11, column 53:
PLS-00302: component 'PAYAMONT' must be declared
ORA-06550: line 11, column 4:
PL/SQL: Statement ignored
ORA-06550: line 12, column 52:
PLS-00302: component 'FIRSTPLEDGE' must be declared
ORA-06550: line 12, column 4:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
With a specific donor it works fine, just doesn't print anything.
DECLARE
lv_pledge_ID DD_PLEDGE.IDPLEDGE%TYPE;
lv_pledge_amount DD_PLEDGE.PLEDGEAMT%TYPE;
lv_num_month_pay DD_PLEDGE.PAYMONTHS%TYPE;
lv_pay_date DATE;
lv_pay_amount NUMBER(6);
lv_frst_pledge DD_PLEDGE.FIRSTPLEDGE%TYPE;
BEGIN
SELECT IDPLEDGE, PLEDGEAMT, PAYMONTHS, PLEDGEDATE, PLEDGEAMT*PAYMONTHS, FIRSTPLEDGE
INTO lv_pledge_ID, lv_pledge_amount, lv_num_month_pay, lv_pay_date, lv_pay_amount, lv_frst_pledge
FROM DD_PLEDGE
WHERE IDDONOR = 302
ORDER BY IDPLEDGE, PLEDGEDATE;
DBMS_OUTPUT.PUT_LINE('pledge ID: ' || lv_pledge_ID);
DBMS_OUTPUT.PUT_LINE('pledge amount: ' || lv_pledge_amount);
DBMS_OUTPUT.PUT_LINE('number of monthly payments: ' || lv_num_month_pay);
DBMS_OUTPUT.PUT_LINE('payment date: ' || lv_pay_date);
DBMS_OUTPUT.PUT_LINE('payment amount: ' || lv_pay_amount);
DBMS_OUTPUT.PUT_LINE('first payment: ' || lv_frst_pledge);
END;
PL/SQL procedure successfully completed.
rec.lv_pledge_ID? rec has onlyIDDONOR, Did you mean to uselv_pledge_ID?LOOP? last one should be removed