Oracle pl/sql 映射值为数组
Oracle pl/sql map with value is array
我需要创建关联数组,其中键是 VARCHAR(20),值是 varchars 数组。
例如:
customer_by_locations: {
"London": {
"John Doe", "Samantha Simpson", "Nicolas Darcula"
},
"Stambul": {
"Abdula Ibn Rahim", "Another Abdula"
}
}
我创建了查询:
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;
但是我有错误
PLS-00382: expression is of wrong type
请告诉我,我将如何在 oracle 中将数组声明为值并在其中赋值 pl/sql。
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;
/
我需要创建关联数组,其中键是 VARCHAR(20),值是 varchars 数组。 例如:
customer_by_locations: {
"London": {
"John Doe", "Samantha Simpson", "Nicolas Darcula"
},
"Stambul": {
"Abdula Ibn Rahim", "Another Abdula"
}
}
我创建了查询:
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;
但是我有错误
PLS-00382: expression is of wrong type
请告诉我,我将如何在 oracle 中将数组声明为值并在其中赋值 pl/sql。
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;
/