The EXISTS method is used to determine whether a specified element exists in a VARRAY or nested table.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL mode.
If the nth element of the collection exists, EXISTS(n) returns TRUE; otherwise, it returns FALSE. If n is out of range, EXISTS returns FALSE without raising the predefined exception SUBSCRIPT_OUTSIDE_LIMIT.
For deleted elements, even if DELETE has reserved a placeholder for them, EXISTS(n) returns FALSE.
Here is an example:
obclient> DECLARE
TYPE emp_id IS TABLE OF NUMBER;
n EMP_ID := emp_id(2,4,6,8);
BEGIN
n.DELETE(2); -- Deletes the second element.
n.TRIM; -- Trims the last element.
FOR i IN 1..5 LOOP
IF n.EXISTS(i) THEN
DBMS_OUTPUT.PUT_LINE('n(' || i || ') = ' || n(i));
ELSE
DBMS_OUTPUT.PUT_LINE('n(' || i || ') has no value');
END IF;
END LOOP;
END;
/
Query OK, 0 rows affected
n(1) = 2
n(2) has no value
n(3) = 6
n(4) has no value
n(5) has no value
The preceding example initializes a nested table with four elements, deletes the second element, trims the last element, and then outputs the values or status of elements 1 through 6.