Closing cursors
Date: 2000/07/21
Message-ID: <8l9p0a$f0c$1_at_nnrp1.deja.com>#1/1
Hi,
[Quoted] [Quoted] usually I close all my cursors in PL/SQL procs as soon as I can, now however I have a case where a procedure will work just fine if I don't close the cursor, but will exit with an ORA-01001: invalid cursor if I try to close it anywhere.
Now I winder if it's okay to leave the code like that or if I'll get into trouble later on for leaving the cursor open.
Here's the code:
CREATE OR REPLACE PROCEDURE Add_To_Depothistory IS BEGIN
DECLARE
CURSOR accountCursor IS
SELECT a.pk_id, a.money, b.rank, Depotsum(a.pk_id) AS
depotvalue, Countshares(a.pk_id) AS sharescount FROM ACCOUNT a, RANKING
b WHERE b.fk_account_id = a.pk_id;
BEGIN
FOR account_rec IN accountCursor LOOP INSERT INTO DEPOTHISTORY (fk_account_id, money, rank, depotvalue, sharescount) VALUES(account_rec.pk_id, account_rec.money,account_rec.rank, account_rec.depotvalue, account_rec.sharescount);
END LOOP;
/*CLOSE accountCursor;*/ COMMIT; END;
END Add_To_Depothistory;
/
This works, as long as I don't uncomment the CLOSE.
It doesn't matter whether I put the close before or after the COMMIT.
Any ideas anyone?
Thanks.
Jens
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Fri Jul 21 2000 - 00:00:00 CEST