PL provides a data structure similar to arrays. This structure can store fixed-sized sequential collections of elements of the same type and orderly data sets.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
An array consists of consecutive memory locations. The least significant digit corresponds to the first element, and the most significant digit corresponds to the last element.
The following example creates an array type by using a command:
CREATE OR REPLACE TYPE varray_type_name IS VARRAY(n) of <element_type>;
The following example dynamically creates an array type in a PL block:
TYPE varray_type_name IS VARRAY(n) of <element_type>;
varray_type_name specifies the name of the array type, n specifies the number of elements, and element_type specifies the element type.
obclient> DECLARE
TYPE alpha IS TABLE OF VARCHAR2(1);
l alpha := alpha('A', 'B', 'C', 'D');
BEGIN
FOR i IN l.FIRST .. l.LAST LOOP
DBMS_OUTPUT.PUT_LINE(l(i));
END LOOP;
DBMS_OUTPUT.PUT_LINE('-');
END;
/
Query OK, 0 rows affected
A
B
C
D
-
A nested table is similar to an array in basic structure. However, they are different in usage:
You must specify the length of an array when you create it, but you do not need to specify the length when you create a nested table. A nested table can be dynamically extended.
An array is continuous. After you delete an element, the subscripts of the subsequent elements in the array decrease by 1. A nested table is continuous during initialization. After you delete an element from the nested table, the subscripts of subsequent elements in the nested table will not be changed and a placeholder holds the original location of the deleted element.