Arrays 值为数组的Oracle pl/sql映射
我需要创建关联数组,其中键是VARCHAR(20),值是VARCHAR数组。 例如:Arrays 值为数组的Oracle pl/sql映射,arrays,oracle,plsql,Arrays,Oracle,Plsql,我需要创建关联数组,其中键是VARCHAR(20),值是VARCHAR数组。 例如: customer_by_locations: { "London": { "John Doe", "Samantha Simpson", "Nicolas Darcula" }, "Stambul": { "Abdula Ibn Rahim", "Another Abdula" } }
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:表达式类型错误
请告诉我,我将如何在oracle pl/sql中将数组声明为值并在其中赋值。您是否尝试过:
list_locations('London'):=“John Doe”、“Samantha Simpson”、“Nicolas Darcula”代码>?是的,我试过这个。同样的错误。哦,我认为你的循环是错误的。。。你不能从1路去伦敦。你想要这个:用于1中的i。。列出位置。计数循环
参见此处示例:感谢您的回复。我真的忘记了数组计数。是的。这是工作。非常感谢您的回复。我真的很感谢你的帮助。
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;
/