Skip to main content
← PL/SQL Topics

Collections

Explain collections of records in PL/SQL

Collections of Records

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

A collection whose element type is a record holds many multi-column rows in memory under one variable.

How it works

Declare TYPE t IS TABLE OF some_record_type (a %ROWTYPE, a cursor%ROWTYPE, or a user-defined RECORD), INDEX BY PLS_INTEGER for an associative array. Access a field as c(i).field_name. You cannot BULK COLLECT into a collection of records if the element is a VARRAY of records used in SQL, but table-of-%ROWTYPE works with BULK COLLECT and with FORALL INSERT ... VALUES c(i). It is the standard shape for staging a batch of rows for bulk DML.

How it works
DECLARE
  TYPE emp_rec IS RECORD (id NUMBER, name VARCHAR2(60), sal NUMBER);
  TYPE emp_tab IS TABLE OF emp_rec INDEX BY PLS_INTEGER;
  c emp_tab;
BEGIN
  c(1).id := 100; c(1).name := 'King'; c(1).sal := 24000;
  c(2).id := 101; c(2).name := 'Kochhar'; c(2).sal := 17000;
  FOR i IN c.FIRST .. c.LAST LOOP
    DBMS_OUTPUT.PUT_LINE(c(i).id || ' ' || c(i).name || ' ' || c(i).sal);
  END LOOP;
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