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 does not support this feature.
If the nth element of the collection exists, the EXISTS(n) method returns TRUE. Otherwise, it returns FALSE. If n is out of range, the EXISTS method returns FALSE without raising the predefined exception SUBSCRIPT_OUTSIDE_LIMIT.
For deleted elements, even if DELETE has reserved a placeholder for them, the EXISTS(n) method 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
In this example, a nested table is initialized with four elements, the second element is deleted, and the last element is trimmed. The values or states of elements 1 through 6 are then output.
