Click to See Complete Forum and Search --> : SQL cursor update of table using variable


silvrwood
May 10th, 2004, 06:57 PM
I have written a procedure that includes a cursor to update a column of a table with a variable. It compiles with errors. Can anyone see where the error is? The one thing I was thinking is that it might be in updating the column equal to the variable I am tracking, as I have not seen this in example before:

CREATE OR REPLACE PROCEDURE xpns_amt
AS
DECLARE
CURSOR c_tot_due
IS
SELECT id, amount, paid
FROM expense;
v_tot_due := 0;
BEGIN
FOR r_tot_due IN c_tot_due
LOOP
v_tot_due := (v_tot_due + (r_tot_due.amount -
r_tot_due.paid));
UPDATE expense
SET total_due = v_tot_due
WHERE id = r_tot_due.id;
DBMS_OUTPUT.PUT_LINE ('The total due is now $'||
v_tot_due);
END LOOP;
END;
END xpns_amt;

hspc
May 12th, 2004, 05:10 AM
what database do you use ?

silvrwood
May 13th, 2004, 01:46 AM
I use Oracle's SQL Plus 9i.

I got a tip to use show errors, which enlightened me on my mistakes.

Thank you.