EXISTS v11
The EXISTS
method verifies that a subscript exists within a collection. EXISTS
returns TRUE
if the subscript exists; if the subscript does not exist, EXISTS
returns FALSE
. The method takes a single argument; the subscript
that you are testing for. The syntax is:
<collection>.EXISTS(<subscript>)
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
.
The following example verifies that subscript number 10
exists within 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 does not exist within the specified collection. Rather than raising an error, the EXISTS
method returns a value of FALSE
.