title: Getting index of element in PL/SQL collection
body: <p>Is there a built-in function to determine the (first) index of an element in a PL/SQL collection?</p>
  
  <p>Something like</p>
  
  <pre><code>DECLARE
    TYPE t_test IS TABLE OF VARCHAR2(1);
    v_test t_test;
  BEGIN
    v_test := NEW t_test('A', 'B', 'A');
    dbms_output.put_line( 'A: ' || get_index( v_test, 'A' ) );
    dbms_output.put_line( 'B: ' || get_index( v_test, 'B' ) );
    dbms_output.put_line( 'C: ' || get_index( v_test, 'C' ) );
  END;
  </code></pre>
  
  <p></p>
  
  <pre><code>A: 1
  B: 2
  C: 
  </code></pre>
  
  <p>I can use Associative Arrays, Nested Tables or Varrays, whatever necessary. If the same element exists more than once, then the index of the first occurrence is sufficient.</p>
  
  <hr>
  
  <p>Otherwise I'd have to do something like</p>
  
  <pre><code>CREATE FUNCTION get_index ( in_test IN t_test, in_value IN VARCHAR2 )
    RETURN PLS_INTEGER
  AS
    i PLS_INTEGER;
  BEGIN
  
  i := in_test.FIRST;
    WHILE( i IS NOT NULL ) LOOP
      IF( in_test(i) = in_value ) THEN
        RETURN i;
      END IF;
  
      i := in_test.NEXT(i);
    END LOOP;
  
    RETURN NULL;
  
  END get_index;
  </code></pre>