PL/SQL bulk collect into associative array with sparse key
Posted
by Dan
on Stack Overflow
See other posts from Stack Overflow
or by Dan
Published on 2010-04-26T18:08:32Z
Indexed on
2010/04/26
18:13 UTC
Read the original article
Hit count: 275
I want to execute a SQL query inside PL/SQL and populate the results into an associative array, where one of the columns in the SQL becomes the key in the associative array. For example, say I have a table Person
with columns
PERSON_ID INTEGER PRIMARY KEY
PERSON_NAME VARCHAR2(50)
...and values like:
PERSON_ID | PERSON_NAME
------------------------
6 | Alice
15 | Bob
1234 | Carol
I want to bulk collect this table into a TABLE OF VARCHAR2(50) INDEX BY INTEGER
such that the key 6
in this associative array has the value Alice
and so on. Can this be done in PL/SQL? If so, how?
© Stack Overflow or respective owner