I know how to make the original procedure run MUCH faster!!!! A lot faster!!
Just code it as follows:
PROCEDURE updt_tab
<b>/*</b>
FOR rec IN (SELECT *
from TABLE1 V
left outer join TABLE2 S
on V.polnum = S.s7poln
AND V.polren = S.s7renn
AND V.polseq = S.s7seqn
AND V.vehnum = S.s7vehn
AND V.linecvg = S.s7lcvg) LOOP
update TABLE1 P
set P.CEDEDPOL = rec.s7ceding
where P.polnum = rec.polnum
and P.polren = rec.polren
and P.polseq = rec.polseq
and P.vehnum = rec.vehnum
and P.linecvg = rec.linecvg
and P.sat = 'ABC';
update TABLE1 P
set P.CEDEDCVG = rec.s7cedecvg
where P.polnum = rec.polnum
and P.polren = rec.polren
and P.polseq = rec.polseq
and P.vehnum = rec.vehnum
and P.linecvg = rec.linecvg
and P.sat = 'ABC';
END LOOP;
COMMIT;<b>
*/ -- we don't need that code at all!!!!!
NULL;</b>
EXCEPTION
WHEN OTHERS THEN
NULL;
END UPDT_TAB; I am not joking.
I am not kidding.
I am not being sarcastic.
I am being 100% honest in my tuning effort.
For you see, with that original code - the follow outcomes are all perfectly acceptable:
a) all rows are read, all rows are updated in both tables and we commit. and then we return.
b) NO rows are read - the first row caused a failure, we do not commit. and then we return
c) 5,000,000 rows are read - this executes 10,000,000 updates, we fail on reading row 5,000,001, we do not commit. and then we return.
Since (a) is acceptable AND (b) is acceptable and (c) is acceptable - I'll just go with (b) (it is by far the most performant!!!) and you are tuned *beyond belief*.
Pretty amazing how easy tuning is - isn't it??? You can go from hours to just milliseconds just like that...
Here read this:
http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/? I just read it today - your exception handling code makes me feel very afraid for you. I usually just say:
http://asktom.oracle.com/pls/asktom/asktom.search?p_string=%22i+hate+your+code%22 "i hate your code", but I was feeling verbose today...
Your new code will not compile.
Why are there two updates???????? you are updating the same record(s), just different columns???? doesn't anyone learn SQL anymore?
There is no reason this code should not be:
merge into table1 p
using (SELECT *
from TABLE1 V
left outer join TABLE2 S
on V.polnum = S.s7poln
AND V.polren = S.s7renn
AND V.polseq = S.s7seqn
AND V.vehnum = S.s7vehn
AND V.linecvg = S.s7lcvg) rec
on (P.polnum = rec.polnum
and P.polren = rec.polren
and P.polseq = rec.polseq
and P.vehnum = rec.vehnum
and P.linecvg = rec.linecvg
and P.sat = 'ABC')
when matched then update set P.CEDEDPOL = rec.s7ceding, P.CEDEDCVG = rec.s7cedecvg ;there should be NO procedural code
there should be NO commit (the client should control that, not a little procedure, it is not smart enough to know "we are truly done"
there should definitely be no "when others then null"