I have a simple PL/SQL procedure, with one cursor and I iterate over it. In each iteration I make an UPDATE statement (after performing some business logic to the data).
However, if there are lots of iterations (tens of thousands), this can get pretty slow, because in every iteration there is single UPDATE statement.
Is there a way to somehow "delay" those updates so that they are executed all at once (and thus much faster).
Edit: Oracle 11
If you can't figure out how to use straight SQL (avoiding the for loop all together) then you will likely be able to improve performance using the BULK Collection features of pl/sql.
Example article here.
Syntax excerpt
LOOP
FETCH c_orders
BULK COLLECT INTO v_order_ids, v_currency_codes, v_amounts_local
LIMIT 100;
EXIT WHEN v_row_count = c_orders%ROWCOUNT;
v_row_count := c_orders%ROWCOUNT;
FOR i IN 1..v_order_ids.count LOOP
v_amounts_usd(i) := currency_convert (v_amounts_local(i),
v_currency_codes(i));
END LOOP;
FORALL i IN 1..v_order_ids.count
UPDATE open_orders /* bulk bind */
SET amount_usd = v_amounts_usd(i)
WHERE order_id = v_order_ids(i);
END LOOP;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With