You can use the EXTEND method to append an element to the end of a variable-size array (or varray) or nested table.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
A collection can be empty but not null. You can use the constructor function to make a collection empty or add elements to a null collection. For more information, see Collection constructor function.
Considerations for EXTEND are as follows:
EXTENDappends a null element to a collection.EXTEND(n)appendsnnull elements to a collection.EXTEND(n,i)appendsncopies of theithelement to a collection.Note
Only
EXTEND(n,i)is applicable to a collection with theNOT NULLconstraint for elements.
EXTEND appends elements based on the internal size of a collection. In other words, if the DELETE method deletes an element but retains a placeholder for this element, EXTEND considers that this element still exists.
Here is an example:
obclient> DECLARE
t nested_type:= nested_type('A', 'B', 'C');
BEGIN
print_t(t);
t.EXTEND(2,1); -- Append two copies of the first element to the collection.
print_t(t);
t.DELETE(4); -- Delete the fourth element.
print_t(t);
t.EXTEND; -- Append 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, initializes and assigns values to three elements, and performs the following operations on the elements:
Append two copies of the first element to the collection.
Delete the fourth element.
Append a null element to the collection.
The print_nt stored procedure outputs the nested table variable after initialization and the EXTEND and DELETE operations.