Skip to content

Instantly share code, notes, and snippets.

@gkazior
Created December 10, 2015 10:47
Show Gist options
  • Save gkazior/cba6eb85faa8c1b60c13 to your computer and use it in GitHub Desktop.
Save gkazior/cba6eb85faa8c1b60c13 to your computer and use it in GitHub Desktop.
DECLARE
TYPE TIdx IS TABLE OF BINARY_INTEGER INDEX BY VARCHAR2(20);
TYPE rec1_ex_TP IS RECORD
(
rec_col1 CHAR(1),
rec_col2 CHAR(1),
rec_col3 CHAR(1)
);
TYPE rec1_ex_ARRAY IS VARRAY(12) OF rec1_ex_TP;
TYPE rec1_TP IS RECORD
(
rec1_ex rec1_ex_ARRAY := rec1_ex_ARRAY()
);
rec1 rec1_TP;
idx TIdx;
i BINARY_INTEGER;
j VARCHAR2(100);
BEGIN
rec1.rec1_ex.EXTEND(3);
-- Sample data
rec1.rec1_ex(1).rec_col1 := 'X';
rec1.rec1_ex(1).rec_col2 := 'A';
rec1.rec1_ex(1).rec_col3 := 'A';
rec1.rec1_ex(2).rec_col1 := 'M';
rec1.rec1_ex(2).rec_col2 := 'B';
rec1.rec1_ex(2).rec_col3 := 'A';
rec1.rec1_ex(3).rec_col1 := 'A';
rec1.rec1_ex(3).rec_col2 := 'C';
rec1.rec1_ex(3).rec_col3 := 'D';
-- prepare index
FOR i IN 1 .. 3
LOOP
idx(rec1.rec1_ex(i).rec_col1) := i;
END LOOP;
-- in order
j := idx.FIRST;
LOOP
EXIT WHEN j IS NULL;
i := idx(j);
dbms_output.put_line(TO_CHAR(j) || '->' || i || '=' || rec1.rec1_ex(i).rec_col1);
j := idx.NEXT(j);
END LOOP;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment