Oracle PL/SQL - LIMIT Collection Method

Introduction

LIMIT returns the maximum number of elements that the collection can have.

If the collection has no maximum number of elements, LIMIT returns NULL.

Only a varray has a maximum size.

The following code prints the values of LIMIT and COUNT for an associative array with four elements, a varray with two elements, and a nested table with three elements.

Demo

SQL>
SQL> DECLARE-- from   ww w. ja v  a 2 s .  c o m
  2    TYPE IntegerListType IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
  3    intList IntegerListType;        -- associative array
  4
  5    TYPE va_type IS VARRAY(4) OF INTEGER;
  6    va  va_type := va_type(2,4);   -- varray
  7
  8    TYPE IntegerListType IS TABLE OF INTEGER;
  9    nt  IntegerListType := IntegerListType(1,3,5);  -- nested table
 10
 11  BEGIN
 12    intList(1):=3; intList(2):=6; intList(3):=9; intList(4):= 12;
 13    DBMS_OUTPUT.PUT('intList.COUNT = '); print(intList.COUNT);
 14    DBMS_OUTPUT.PUT('intList.LIMIT = '); print(intList.LIMIT);
 15
 16    DBMS_OUTPUT.PUT('va.COUNT = '); print(va.COUNT);
 17    DBMS_OUTPUT.PUT('va.LIMIT = '); print(va.LIMIT);
 18
 19    DBMS_OUTPUT.PUT('nt.COUNT = '); print(nt.COUNT);
 20    DBMS_OUTPUT.PUT('nt.LIMIT = '); print(nt.LIMIT);
 21  END;
 22  /
intList.COUNT = 4
intList.LIMIT = NULL
va.COUNT = 2
va.LIMIT = 4
nt.COUNT = 3
nt.LIMIT = NULL

PL/SQL procedure successfully completed.

SQL>