Oracle pl / sql map with value - array

I need to create an associative array where the key is VARCHAR (20) and value is a varchars array. For example:

customer_by_locations: {
   "London": {
               "John Doe", "Samantha Simpson", "Nicolas Darcula"
             },
   "Stambul": {
               "Abdula Ibn Rahim", "Another Abdula"
             }
}

      

I created a request:

declare 
  type customers is varray(10) of varchar2(20);
  type locations is table of customers index by varchar2(20);

  list_locations locations;
  list_customers varchar(20);
begin
  list_locations('London') := ("John Doe", "Samantha Simpson", "Nicolas Darcula");
  list_locations('Stambul') := ("Abdula Ibn Rahim", "Another Abdula");

  for i in 1 .. list_locations loop
    DBMS_OUTPUT.PUT_LINE('Total ' || list_locations(i));   
    //Something do 
  end loop;  
end; 

      

But I have a mistake

PLS-00382: Invalid Expression Type

Please tell me how I will declare array as value and assign values ​​to it in oracle pl / sql.

+3


source to share


1 answer


declare 
  type customers is varray(10) of varchar2(20);
  type locations is table of customers index by varchar2(20);

  list_locations locations;
  list_customers varchar(20);
  v_location varchar2(20);
begin
  list_locations('London') := customers('John Doe', 'Samantha Simpson', 'Nicolas Darcula');
  list_locations('Stambul') := customers('Abdula Ibn Rahim', 'Another Abdula');

  v_location := list_locations.first;
  loop
    exit when v_location is null;

    for i in 1 .. list_locations(v_location).count loop
      dbms_output.put_line(v_location||': '||list_locations(v_location)(i));
    end loop;

    v_location := list_locations.next(v_location);
  end loop;
end; 
/

      



+3


source







All Articles