The EXTEND method appends elements to the end of a VARRAY or nested table.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
A collection can be empty but cannot be NULL. You can use a constructor to make a collection empty or to append 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 aNOT 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 are some examples:
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
---
The preceding example declares a nested table variable and initializes it with three elements. It then performs the following operations:
Appends two copies of the first element to the collection.
Deletes the fourth element.
Appends a NULL element to the collection.
The print_nt stored procedure outputs the nested table variable after initialization and after the EXTEND and DELETE operations.
