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