The EXTEND method appends 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-compatible mode.
A collection can be empty, but not 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 whose elements are constrained by theNOT NULLclause.
The EXTEND method operates based on the internal size of the collection. In other words, if DELETE removes an element but leaves 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. 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 it is initialized and after the EXTEND and DELETE operations.