You can use the TRIM method to trim elements from 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 MySQL mode.
Usage notes for TRIM:
TRIMwill trim one element from the end of a collection. Therefore, the collection must contain at least one element. Otherwise, the predefined exceptionSUBSCRIPT_BEYOND_COUNTwill be raised.TRIM(n)will trimnelements from the end of a collection. Therefore, the collection must contain at leastnelements. Otherwise, the predefined exceptionSUBSCRIPT_BEYOND_COUNTwill be raised.
TRIM trims 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, TRIM considers that this element still exists. Therefore, you can use TRIM to trim a deleted element.
PL does not retain placeholders for trimmed elements. Therefore, trimmed elements are not counted in the internal size of a collection, and you cannot recover trimmed elements by assigning valid values to them.
Notice
PL does not depend on the interactions between TRIM and DELETE. Consider a nested table as a fixed-size array that supports only the DELETE method, or as a stack that supports only the TRIM and EXTEND methods.
Example:
obclient> DECLARE
t nested_type:= nested_type('A', 'B', 'C', 'D', 'E', 'F');
BEGIN
print_t(t);
t.TRIM; -- Trim the last element.
print_t(t);
t.DELETE(3); -- Delete the third element.
print_t(t);
t.TRIM(2); -- Trim the last two elements.
print_t(t);
END;
/
Query OK, 0 rows affected
t.(1) = A
t.(2) = B
t.(3) = C
t.(4) = D
t.(5) = E
t.(6) = F
---
t.(1) = A
t.(2) = B
t.(3) = C
t.(4) = D
t.(5) = E
---
t.(1) = A
t.(2) = B
t.(4) = D
t.(5) = E
---
t.(1) = A
t.(2) = B
---
The preceding example declares a nested table variable, initializes and assigns values to six elements, and performs the following operations on the elements:
Trim the last element.
Delete the fourth element.
Trim the last two elements.
The print_nt stored procedure outputs the nested table variable after initialization and the TRIM and DELETE operations.