Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: commit after or before close cursor - best practise

Re: commit after or before close cursor - best practise

From: DA Morgan <damorgan_at_psoug.org>
Date: Sat, 19 Nov 2005 06:39:21 -0800
Message-ID: <1132411162.412679@yasure>


Grzegorz Goryszewski wrote:
> Hello,
>
> which is better from 'best practise' perspective:
>
> declare
> cursor ...
>
> begin
> open ...
> loop
> fetch ...
> exit when %NOTFOUND
> insert ...
> end loop;
> commit;
> close ...
>
>
> OR
>
> declare
> cursor ...
>
> begin
> open ...
> loop
> fetch ...
> exit when %NOTFOUND
> insert ...
> end loop;
> close ...
> commit;
>
> Regards.
> Grzegorz

Better ... well really best ... is to stop using cursor loops at all except in very rare circumstances. It is highly preferable to use array processing with BULK COLLECT and FORALL.

My personal preference with cursor loops, when I do have occassion to use them is to commit first. This being based on the fact that if something were to go terribly wrong ... I want my changes to be committed to the database as soon as possible. Not a big difference, and not something that has ever bought me anything, but conceptually I like it that way.

-- 
Daniel A. Morgan
http://www.psoug.org
damorgan_at_x.washington.edu
(replace x with u to respond)
Received on Sat Nov 19 2005 - 08:39:21 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US