Getting index of element in PL/SQL collection
Is there a built-in function to determine the (first) index of an element in a PL/SQL collection?

Something like

    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;
<foo/>

    A: 1
    B: 2
    C: 
I can use Associative Arrays, Bested Tables or Varrays, whatever necessary. If the same element exists more than once, then the index of the first occurrence is sufficient.

---

Otherwise I'd have to do something like

    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;


Getting index of element in PL/SQL collection
===

Is there a built-in function to determine the (first) index of an element in a PL/SQL collection?

Something like

    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;
<foo/>

    A: 1
    B: 2
    C: 
I can use Associative Arrays, Bested Tables or Varrays, whatever necessary. If the same element exists more than once, then the index of the first occurrence is sufficient.

---

Otherwise I'd have to do something like

    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;

