Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

In PL/SQL, suppose I have some associative array defined as follows:

declare 
       type a_arr_t is table of PLS_INTEGER index by PLS_INTEGER;
       a_arr a_arr_t;

I then, sparsely, populate the array as follows:

begin
      a_arr(1)   := 2;
      a_arr(10)  := 4;
      a_arr(100) := 6;
end;

Is there some operator or function that can give me the indices of the array, (1,10,100) as a collection of some sort, something like indices of in a forall statement?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

Is there some operator or function that can give me the indices of the array

No, you have to loop through the associative array:

declare 
       type a_arr_t is table of PLS_INTEGER index by PLS_INTEGER;
       type keys_t is table of PLS_INTEGER;
       a_arr a_arr_t;
       keys_ keys_t := keys_t();
       l_index integer;
begin
      a_arr(1)   := 2;
      a_arr(10)  := 4;
      a_arr(100) := 6;

      l_index := a_arr.first;
      while (l_index is not null)
      loop
          keys_.extend();
          keys_(keys_.count):=l_index;
          dbms_output.put_line(keys_(keys_.count));
          l_index := a_arr.next(l_index);
      end loop;
end;
/

/*
1
10
100
*/
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.