Collection.exists()

The PL/SQL method collection.exists() could be called on associative array, nested table, varray to check if an element is in the current collection.

It does not throw any exception. Even if the undelying collection has not been initialized, it just returns FALSE.

If parents_t is a varray type available to the current PL/SQL, we could write this code:

declare
parents parents_t := parents_t();
begin
if parents.exists(42) = false then
dbms_output.put_line('This item is not in the collection');
end if;
end;

That prints the message, since that element is not in the collection. More interestingly, even though we don't initialize the varray but just declar it:
parents parents_t;
the result won't change.

Chapter 12 of Oracle PL/SQL Programming, fifth edition, by Steven Feuerstein is all about collections.

No comments:

Post a Comment