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

Home -> Community -> Usenet -> c.d.o.server -> Re: cursor looping - best practices?

Re: cursor looping - best practices?

From: <fitzjarrell_at_cox.net>
Date: Fri, 15 Jun 2007 10:30:18 -0700
Message-ID: <1181928618.835647.326230@q69g2000hsb.googlegroups.com>


On Jun 15, 11:36 am, spacemar..._at_mailinator.com wrote:
> On Jun 15, 11:11 am, sybra..._at_hccnet.nl wrote:
>
> > Obviously this is a version dependent question.
>
> not so obvious at all -- otherwise i would have specified. i was
> unaware of that difference between version. thanks.
>
> > I always failed to see why people posting here assume everyone here
> > is a mindreader and/or keeps track of versions in use.
>
> perhaps i can offer you some insight. i come from the MS SQL world,
> and little has changed over the years... what i learned in 2000 is
> still what i use today in MS SQL, little has changed. in fact its not
> uncommon to find SQL Server 2000 db instances in production use. i
> dont know about previous versions because they are no longer found in
> production in my experiences.
>
> i cant speak for others, but thats why when i ask about a best
> practice its not obviously apparent to me that there may be dramatic
> differences between what people are actively using in production.
>
> > So the best practice is NOT to use CURSOR FOR loops.
>
> interesting. i am reviewing some found-code and i see a technique like
> so:
>
> LOOP
> IF c_someCursor%FOUND THEN
> --doing stuff: CASE value tests, dynamic variable
> assignments..
> END IF
> END LOOP
>
> ...it almost seems like an app programmer style, and not what ive
> typically seen in T-SQL, so im curious about it w/ regards to PL SQL
>
> thanks for the info.
>
> sm

The code you cite is, well, OLD code. I haven't written a loop like that in years, what with the FOR and WHILE constructs available:

FOR myrec IN cursor LOOP

     .... processing here
END LOOP; No manual checking for the end of the data, no manual exit strategy.

For array processing a concise set of examples can be found at:

http://www.psoug.org/reference/array_processing.html

A visit to the above link would be well worth your time.

David Fitzjarrell Received on Fri Jun 15 2007 - 12:30:18 CDT

Original text of this message

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