|
|
Oracle Database 10g allows you to use MEMBER OF syntax to determine if a particular values is a "member of" a nested table. Here is an example:
DECLARE
TYPE clientele IS TABLE OF VARCHAR2 (64);
client_list_12 clientele :=
clientele ('Customer 1', 'Customer 2');
BEGIN
IF 'Customer 1' MEMBER OF client_list_12
THEN
DBMS_OUTPUT.put_line ('Customer 1 is in the 12 list');
END IF;
IF 'Customer 3' NOT MEMBER OF client_list_12
THEN
DBMS_OUTPUT.put_line ('Customer 3 is not in the 12 list');
END IF;
END;
/
That's all very wonderful – unless you are not yet running Oracle Database 10g or you are working with associative arrays (declared with INDEX BY syntax), which includes many of us. So I built a general template into Qnxo that allows you to generate a function that accepts a collection of the type you specify at time of generation, and a value, and returns TRUE if that value is found in an index of the collection. If you have installed Qnxo, search for Universal ID {5ADA17C8-60A3-47D3-993F-72A673393909} in Explorer. You can then generate a function for your specific type.
For the rest of you, I have generated a function that works with DBMS_SQL.VARCHAR2S. You can replace references to this type with your own collection type, and then use it in your own environment. This download also includes test scripts (for utPLSQL and native PL/SQL execution) to verify that the program works correctly.