The EXTEND method is used to add elements to the end of a variable-length array or nested table.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL mode.
A collection can be empty but not null. You can use a constructor to make a collection empty or add elements to a null collection. For more information, see Collection constructors.
The EXTEND method is used as follows:
EXTENDappends a null element to the collection.EXTEND(n)appendsnnull elements to the collection.EXTEND(n, i)appendsncopies of theith element to the collection.Note
Only
EXTEND(n, i)can be used for collections with elements that have theNOT NULLconstraint.
The EXTEND method operates based on the internal size of the collection. That is, if DELETE removes an element but retains a placeholder for it, EXTEND considers the element to still exist.
Here is an example:
obclient> DECLARE
t nested_type:= nested_type('A', 'B', 'C');
BEGIN
print_t(t);
t.EXTEND(2,1); -- Appends two copies of the first element to the collection.
print_t(t);
t.DELETE(4); -- Deletes the fourth element.
print_t(t);
t.EXTEND; -- Appends a null element to the collection.
print_t(t);
END;
/
Query OK, 0 rows affected
t.(1) = A
t.(2) = B
t.(3) = C
---
t.(1) = A
t.(2) = B
t.(3) = C
t.(4) = A
t.(5) = A
---
t.(1) = A
t.(2) = B
t.(3) = C
t.(5) = A
---
t.(1) = A
t.(2) = B
t.(3) = C
t.(5) = A
t.(6) = NULL
---
In the preceding example, a nested table variable is declared and initialized with three elements. The following operations are performed:
Two copies of the first element are appended to the collection.
The fourth element is deleted.
A null element is appended to the collection.
The print_nt stored procedure outputs the nested table variable after initialization and after EXTEND and DELETE operations.