Skip to main content
← PL/SQL Topics

Cursors & Bulk Operations

Explain FORALL with INDICES OF and VALUES OF

FORALL with INDICES OF and VALUES OF

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

These clauses let FORALL iterate a sparse driving collection, or follow an index collection that points into another.

How it works

Plain FORALL i IN 1 .. c.COUNT fails if the collection is sparse (gaps from DELETE). FORALL i IN INDICES OF c iterates only the subscripts that actually exist. FORALL i IN VALUES OF idx_coll uses the values stored in idx_coll as the subscripts into the DML collection — useful when a first pass builds a list of 'rows that passed validation' and the second pass only binds those.

How it works
DECLARE
  TYPE num_tab IS TABLE OF NUMBER;
  l_ids   num_tab := num_tab(101,102,103,104,105);
  l_keep  num_tab := num_tab();
BEGIN
  l_ids.DELETE(3);                        -- make it sparse
  FORALL i IN INDICES OF l_ids
    UPDATE employees SET salary = salary + 100 WHERE employee_id = l_ids(i);

  l_keep := num_tab(1, 2, 5);             -- subscripts to process
  FORALL i IN VALUES OF l_keep
    UPDATE employees SET commission_pct = 0.1 WHERE employee_id = l_ids(i);
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI