Re: Closing cursors

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: 2000/07/21
Message-ID: <964196269.9268.0.pluto.d4ee154e_at_news.demon.nl>#1/1


You are using a cursor for loop.
A cursor for loop takes care of both the open *and* the close. If you don't use a cursor for loop, you'll need to close them explicitly.

Hth,

Sybrand Bakker, Oracle DBA

<jba_lixx_at_my-deja.com> wrote in message news:8l9p0a$f0c$1_at_nnrp1.deja.com...
> Hi,
>
> 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

Original text of this message