gpt4 book ai didi

arrays - 值为数组的 Oracle pl/sql 映射

转载 作者:行者123 更新时间:2023-12-01 00:56:02 30 4
gpt4 key购买 nike

我需要创建关联数组,其中键是 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;
/

关于arrays - 值为数组的 Oracle pl/sql 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27908998/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com