Oracle11gRelease1 (11.1) PLSQL _ multi-dimensional Collection type and its exceptions. Although the collection only has one dimension, it can model a multi-dimensional Collection. Create 1
Oracle 11g Release 1 (11.1) PL/SQL _ multi-dimensional Collection type and its exceptions. Although the collection only has one dimension, it can model a multi-dimensional Collection. Create 1
Content
Multi-dimensional Collection
Although collection only has one dimension, it can model one dimension. Create a collection, and each element is also a collection. For example, create a varray nested table, a varray, and a nested table varray.
Example 1: multi-dimensional varray
DECLARETYPE t1ISVARRAY (10)OF INTEGER; TYPE nt1ISVARRAY (10)OFT1;-- Multilevel varray typeVa t1: = t1 (2, 3, 5 );-- Initialize multilevel varrayNva nt1: = nt1 (va, t1 (55,6, 73), t1 (2, 4), va); IINTEGER; Va1 t1;BEGIN -- Multilevel accessI: = nva (2) (3 );-- I will get value 73DBMS_OUTPUT.PUT_LINE ('I ='| I );-- Add a new varray element to nvaNva. EXTEND;-- Replace inner varray elementsNva (5): = t1 (56, 32); nva (4): = t1 (45, 43, 67,43345 );-- Replace an inner integer elementNva (4) (4): = 1;-- Replaces 43345 with 1 -- Add a new element to the 4th varray element -- And store integer 89 into it.Nva (4). EXTEND; nva (4) (5): = 89;END;/
Example 2: demonstrate multi-dimensional nested table
VARCHAR2 (20); TYPE Ntb1 tb1; tv1;-- Table of varray elementsVtb1 tb1: = tb1 ('One','Three'); Vntb1 ntb1: = ntb1 (vtb1); vntb2 ntb2: = ntb2 (tv1 (3, 5), tv1 (5, 7, 3 ));-- Table of varray elementsBEGINVntb1.EXTEND; vntb1 (2): = vntb1 (1 );-- Delete the first element in vntb1Vntb1.DELETE(1 );-- Delete the first string -- From the second table in the nested tableVntb1 (2 ).DELETE(1 );END;/
Example 3: multi-dimensional associative array
PLS_INTEGER; tb1 va1INDEX BYPLS_INTEGER; v1 va1: = va1 ('Hello','World'); V2 ntb1; v3 ntb2; v4 tb1; v5 tb1;-- Empty tableBEGINV4 (1): = 34; v4 (2): = 46456; v4 (456): = 343; v2 (23): = v4; v3 (34 ): = va1 (33,456,656,343 );-- Assign an empty table to v2 (35) and try againV2 (35): = v5; v2 (35) (2): = 78;-- It works nowEND;/