当处理大量记录时,单独记录日志



我有一个程序,它将根据现有订单列表分配产品。

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

我尝试了以下两种方法。

  1. Bulk Collect:我通过加入Order_Master &Product_Master。然后使用Bulk-Collect来插入赋值。然而,我正在失去伐木&;个人记录跟踪。
  2. For循环:我使用的For循环如上所述。但这花的时间太长了。我的执行时间增加了很多倍。

我希望处理与日志&跟踪。如有任何帮助,不胜感激。

对我来说,这里的问题似乎是您试图将大量行处理与单行日志记录相结合。这导致性能非常差,因为Oracle必须不断地在PL/SQL和SQL引擎之间切换。

因此,一个可行的解决方案是在一个数组TYPE t_logs IS TABLE OF reasonable_rec_log_type中收集日志信息,并根据预期的表维度,将其一次性或不时地以块形式传递给日志过程(在外部循环中?)。

如果您决定使用批量收集解决方案,如果您自己执行insert来记录日志,那么也可以使用FORALL(多次),因为它不会在调用过程时加速—它意味着生成将每次执行一行的DML语句并将它们一起执行。

最新更新