Oracle PL/SQL - PL SQL Data Type Multidimensional Collections

Introduction

You can model a multidimensional collection with a collection whose elements are collections.

In the following code, my is a two-dimensional varray-a varray of varrays of integers.

Demo

SQL>
SQL>-- from w ww  . ja va2  s . c  om
SQL> DECLARE
  2    TYPE t1 IS VARRAY(10) OF INTEGER;  -- varray of integer
  3    va t1 := t1(2,3,5);
  4
  5    TYPE nt1 IS VARRAY(10) OF t1;      -- varray of varray of integer
  6    my nt1 := nt1(va, t1(55,6,73), t1(2,4), va);
  7
  8    i INTEGER;
  9    va1 t1;
 10  BEGIN
 11    i := my(2)(3);
 12    DBMS_OUTPUT.PUT_LINE('i = ' || i);
 13
 14    my.EXTEND;
 15    my(5) := t1(56, 32);          -- replace inner varray elements
 16    my(4) := t1(45,43,67,43345);  -- replace an inner integer element
 17    my(4)(4) := 1;                -- replace 43345 with 1
 18
 19    my(4).EXTEND;    -- add element to 4th varray element
 20    my(4)(5) := 89;  -- store integer 89 there
 21  END;
 22   /
i = 73

PL/SQL procedure successfully completed.

SQL>

Related Topic