Skip to main content
← PL/SQL Topics

Cursors & Bulk Operations

Explain BULK COLLECT INTO a collection of records

BULK COLLECT INTO a Collection of Records

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

One collection whose element type is a record (often %ROWTYPE) can capture whole rows in a single fetch.

How it works

Instead of parallel collections (one per column), declare TYPE t IS TABLE OF table%ROWTYPE (or of a cursor%ROWTYPE, or of a user record) and BULK COLLECT INTO a single variable of that type. It reads cleaner, keeps the fields together, and feeds straight into FORALL ... INSERT INTO t VALUES l_rows(i). Combine with LIMIT for large sources.

How it works
DECLARE
  CURSOR c IS SELECT employee_id, last_name, salary FROM employees;
  TYPE emp_tab IS TABLE OF c%ROWTYPE;
  l_emps emp_tab;
BEGIN
  OPEN c;
  LOOP
    FETCH c BULK COLLECT INTO l_emps LIMIT 500;
    EXIT WHEN l_emps.COUNT = 0;
    FOR i IN 1 .. l_emps.COUNT LOOP
      DBMS_OUTPUT.PUT_LINE(l_emps(i).last_name || ' = ' || l_emps(i).salary);
    END LOOP;
    EXIT WHEN c%NOTFOUND;
  END LOOP;
  CLOSE c;
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