Oracle – Example of Associative Array

0
1113
Oracle Database

This is light weight way to manage key value pairs

DECLARE

    TYPE my_array is TABLE OF x INDEX BY BINARY_INTEGER;

    l_my_array my_array ;

    l_index BINARY_INTEGER;

BEGIN

    –To traverse the array:

    l_index := array_name.FIRST;

    WHILE l_index IS NOT NULL LOOP

        — access the array element

        dbms_output.put_line(  l_my_array (l_index));

        l_index := l_my_array .NEXT(l_index);

    END LOOP;

EXCEPTION

    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(SQLERRM);
    DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
   RAISE;
   ROLLBACK;

END;

https://www.oracletutorial.com/plsql-tutorial/plsql-associative-array/