EXISTS v16

The EXISTS method verifies that a subscript exists in a collection. EXISTS returns TRUE if the subscript exists. If the subscript doesn't exist, EXISTS returns FALSE.

Syntax

The method takes a single argument: the subscript that you are testing for. The syntax is:

<collection>.EXISTS(<subscript>)

Where:

collection is the name of the collection.

subscript is the value that you are testing for. If you specify a value of NULL, EXISTS returns false.

Example

This example verifies that subscript number 10 exists in the associative array:

DECLARE
    TYPE sparse_arr_typ IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    sparse_arr      sparse_arr_typ;
BEGIN
    sparse_arr(-100)  := -100;
    sparse_arr(-10)   := -10;
    sparse_arr(0)     := 0;
    sparse_arr(10)    := 10;
    sparse_arr(100)   := 100;
    DBMS_OUTPUT.PUT_LINE('The index exists: ' ||
        CASE WHEN sparse_arr.exists(10) = TRUE THEN 'true' ELSE 'false' END);
END;

The index exists: true

Some collection methods raise an exception if you call them with a subscript that doesn't exist in the specified collection. Rather than raising an error, the EXISTS method returns a value of FALSE.