Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Help with simple PL/SQL
DA Morgan wrote:
> DFS wrote:
>> DA Morgan wrote: >> >>> William Robertson wrote: >>> >>>> You can simplify it even firther with something like (untested): >>>> >>>> CREATE OR REPLACE PROCEDURE setlistorder >>>> ( p_projectid INTEGER ) >>>> IS >>>> i INTEGER := 1; >>>> BEGIN >>>> FOR r IN >>>> ( >>>> SELECT projcpid, itemorder >>>> FROM table_project >>>> WHERE projid = projectid >>>> ORDER BY itemorder >>>> ) >>>> LOOP >>>> UPDATE table_project >>>> SET itemorder = i >>>> WHERE projcpid = r.projcpid; >>>> >>>> i := i + 1; >>>> END LOOP; >>>> END; >>>> >>>> However I might have missed what all the variables were for. It >>>> also seems like something you should be able to do with a straight >>>> UPDATE statement. >>> >>> Why would you use a cursor loop to do what could be done 100X faster >>> with array processing? >> >> >> 100x sounds exaggerated, don't you think DA? Notice each iteration >> contains an update statement. >> >> In case you're interested, that loop will operate on no more than 300 >> records. It currently executes in half a second or so. >> >> But I'm curious what the array processing code would look like. >
>
>
>
>
>
>> END LOOP;
> INSERT INTO parent VALUES (j+i, k);
>
>
>
>
>
>
>> END LOOP;
> FORALL i IN 1..l_data.COUNT
> INSERT INTO child VALUES l_data(i);
>
> EXIT WHEN c%NOTFOUND;
>
>
>
>
>
Wow. 18x speedup is plenty awesome.
I ran your code and got 1.04 and 0.01 for the slow and fast ways (I'm running Oracle 9.2).
The procedure I use, with the cursor loop as Will Robertson suggested, registers Elapsed: 00:00:00.00 so I don't think array processing will be a time-saver for my small datasets.
(btw, I know you like Access, so I'll tell you it takes Access about 4 seconds using the cursor loop equivalent, and about 2 seconds using DAO recordset edits)
The more I use Oracle the better I think of it. It's just a fantastic dbms.
Thanks for the demo - I may be able to incorporate those techniques in other ways. Received on Thu Oct 13 2005 - 19:44:42 CDT