How to check if an array contains a particular string?

user1394523 picture user1394523 · Jan 29, 2013 · Viewed 33.3k times · Source

I have an array of strings. I want to check if a particular string is present in the array.

DECLARE
  TYPE v_array IS TABLE OF VARCHAR2(200);
  ais_array v_array;
BEGIN
  ais_array := ('Lb1','Lb2','Lb3','Lb613');
  IF 'Lb1' IN ais_array THEN
     dbms_output.put_line('found');
  END IF;
END;

The IN operator is not working. I tried doing a select * on the type and then using IN but that didn't work either.

Any suggestions?

Answer

Egor Skriptunoff picture Egor Skriptunoff · Jan 29, 2013

Try member of condition:

IF 'Lb1' member of ais_array THEN
  dbms_output.put_line('found');
END IF;

Oracle introduced several set operators for working with collections in 10g. Please read the documentation to learn more.