i'm looking for more efficient ways to loop through PLSQL.
Requirements: imagine that i have BudgetTable & RuleSet table. Ruleset looks something like this:
acc | loc | proj || rule1 | tag1 | prio
A1% | L1% | P2% || direct | all | 90
A12% | L12% | P23% || spread | alloc | 50
the first 3 columns are the where clause for the BudgetTable keys below, and store the rest of the columns..
A123 | L123 | P234
A199 | L199 | P299
and the records being picked up for each loop iteration
loop1: (A1% | L1% | P2% || direct | all | 90)
A123 | L123 | P234 || direct | all | 90
A199 | L199 | P299 || direct | all | 90
loop2: (A12% | L12% | P22% || spread | alloc | 50)
A123 | L123 | P234 || spread | alloc | 50
I've done the most straightforward way, by iterating through the RuleSet table.
(pseudocodes)
FOR r in (select acc,loc,proj,rule1,tag1,prio from RuleSet)
LOOP
INSERT INTO ResultTable
select [columns, rule, tag1,prio ]
from BudgetTable
where acc like r.acc
and loc like r.loc
and proj like r.proj
;
END LOOP;
I am looking for better ways to do this. the problem is the RuleSet can contain several thousands rules, so iterating through & matching the records one-by-one can be lengthy. I was wondering if it's possible to break the loop in several parallel stream & simultaneously run them .. Thanks for the input..