Tuesday, October 20, 2015

Oracle Multidimensional Collections

Multidimensional Collections

In addition to regular data types, collections can be based on record types, allowing the creation of two-dimensional collections.
 
DECLARE
  TYPE t_row IS RECORD (
    id  NUMBER,
    description VARCHAR2(50)
  );

  TYPE t_tab IS TABLE OF t_row;
  l_tab t_tab := t_tab();
BEGIN
  FOR i IN 1 .. 10 LOOP
    l_tab.extend();
    l_tab(l_tab.last).id := i;
    l_tab(l_tab.last).description := 'Description for ' || i;
    :result := :result||' '||l_tab(l_tab.last).id||'    -    '||l_tab(l_tab.last).description||chr(10);
  END LOOP;
END; 

No comments:

Post a Comment