0

I am having a procedure that will assign Products against Existing List of Orders.

For rec_ord in(Select Order_ID,Order_Prop1,Order_Prop2,<some more columns> 
               from Order_Master Where <Some Conditions>)
Loop
<Step-1:Do some Processing on Order_Prop1,Order_Prop2>
[Log the Processing Result]
For rec_prod in (Select Prod_ID,Prod_Prop1,Prod_Prop2,<some more columns> 
                 from Product_Master 
                 Where Prod_Prop1 = Ord_Prop1
                 and <Some Conditions>)
Loop
<Step-2:Do Some Processing using Prod_Prop2 and Order_Prop2>
[Log the Processing Result]
<Decide Whether to Assign or Not>
[Log the assignment or non-assignment with reason]
End Loop
End Loop

I tried below 2 methods.

  1. Bulk Collect:I Combined Step-1&2 in the single query by joining Order_Master & Product_Master. And then Using Bulk-Collect to insert the assignment. However I am losing the Logging & Tracking of individual Record.
  2. For Loop: I used For Loop as given above. But this is taking way too long. Increasing my Execution time by many times.

I want the Processing to be fast along with the logging & tracking. Any Help is appreciated.

Thanx in advance.

Debabrata
  • 162
  • 9

1 Answers1

0

For me, the problem here seems to be that you try to combine mass-row processing with single-row logging. This leads to very poor performance, as Oracle has to switch between PL/SQL and SQL engine constantly.

Therefore, a feasible solution would be to collect the logging information in an array TYPE t_logs IS TABLE OF reasonable_rec_log_type and pass it to a logging procedure at once or in chunks from time to time (in the outer loop?), depending on the prospective table dimensions.

If you decide for a bulk collect solution, using FORALL (multiple times) would also be possible if you did the Inserts for logging yourself, as it will not speed up when calling a procedure - it's meant to generate the DML statements that would have been executed one row at a time and execute them altogether.

RicmanX
  • 36
  • 3