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

Home -> Community -> Usenet -> c.d.o.tools -> Re: PL/SQ Cursor LOOP problem

Re: PL/SQ Cursor LOOP problem

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Mon, 26 Mar 2001 18:51:44 +0200
Message-ID: <tbutvr1g98fb2a@beta-news.demon.nl>

"Larry Tucker" <lrayt_at_swbell.net> wrote in message news:3ABF3E35.A7B601E8_at_swbell.net...
> Hello.
>
> I'm new to Oracle programming. Will someone please help me
>
> find a simple, elegant way to perform a cursor loop in PL/SQL
>
> to do the following?
>
>
>
> Suppose for discussion purposes each record in cursor c_Main
>
> has a Group designation column with values G1, G2, .G?
>
> (In fact the group values are character strings. No numeric index
>
> of any kind is available from the group designations.)
>
> For thousands of records in cursor c_Main, with an unknowable
>
> number of groups, G1, G2, ., G?.
>
> Read records from cursor c_Main that belong to group G1, making a
>
> series of calculations until all records from c_Main in G1 are read,
>
> then write a single record of values for G1 to TABLE_RESULT,
>
> then read records from c_Main belonging to group G2, making a
>
> series of calculations until all records from c_Main in G2 are read,
>
> then write a single record of values for G2 to TABLE_RESULT, etc.
>
> Repeat for G3, G4, . ?, until all groups are exhausted.
>
>
>
> The TABLE_RESULT would have a single record for each group in
>
> cursor c_Main. So, if there are 247 groups in cursor c_Main, there
>
> would be 247 records in TABLE_RESULT.
>
>
>

It is always a very bad idea (tm) to anything in pl/sql which you could have done as well (and easily) in SQL.
The reason for this is quite simple: a fetch (happens in your cursor for loop) is very expensive.
So maybe you should either provide more detail, so you can get a really working example, and/or reconsider
doing it in pl/sql. From your description it looks like one single
insert into
select
from
group by
should me more than sufficient.

Hth,

Sybrand Bakker, Oracle DBA Received on Mon Mar 26 2001 - 10:51:44 CST

Original text of this message

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