Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map data structure in pl/sql for storing key value pair?

Is there anyway to create a map data structure in pl/sql.

like image 936
yesraaj Avatar asked Apr 28 '10 09:04

yesraaj


1 Answers

There is the PL/SQL associative array

DECLARE
  TYPE salary_tab_t IS TABLE OF NUMBER INDEX BY VARCHAR2(30);
  salary_tab salary_tab_t;
BEGIN
  salary_tab('JONES') := 10000;
  salary_tab('SMITH') := 12000;
  salary_tab('BROWN') := 11000;
END;

You can loop through the elements like this:

  l_idx := salary_tab.FIRST;
  LOOP
    EXIT WHEN l_idx IS NULL;
    dbms_output.put_line (salary_tab(l_idx));
    l_idx := salary_tab.NEXT(l_idx);
  END LOOP;
like image 94
Tony Andrews Avatar answered Oct 02 '22 04:10

Tony Andrews