问题描述
Hi,
In the below example for Associative Array Indexed by String,
set serveroutput on;
DECLARE
-- Associative array indexed by string:
TYPE population IS TABLE OF NUMBER -- Associative array type
INDEX BY VARCHAR2(64); -- indexed by string
city_population population; -- Associative array variable
i VARCHAR2(64); -- Scalar variable
BEGIN
-- Add elements (key-value pairs) to associative array:
city_population('Smallville') := 2000;
city_population('Midland') := 750000;
city_population('Megalopolis') := 1000000;
-- Change value associated with key 'Smallville':
city_population('Smallville') := 2001;
-- Print associative array:
i := city_population.FIRST; -- Get first element of array
WHILE i IS NOT NULL LOOP
DBMS_Output.PUT_LINE
('Population of ' || i || ' is ' || city_population(i));
i := city_population.NEXT(i); -- Get next element of array
END LOOP;
END;
/
OP:
PL/SQL procedure successfully completed.
Population of Megalopolis is 1000000
Population of Midland is 750000
Population of Smallville is 2001
/
What ever the values I change for city_population the FIRST element of this array remain the same to
'Population of Megalopolis is 1000000'
I dono why.
My problem here is about this line "city_population.FIRST;" here the FIRST keyword refers too.. it refers too highest value associated with elements or ?? the reason is every time I run this block with different combinations I get Megalopolis as output.
Sorry for the confusion. Please do let me know if any clarifications again!
Thanks 专家解答
你是什么意思 “我为城市人口改变了什么值”
你给了我们你的代码-太好了。但是你需要给我们举一个例子,说明你在哪里遇到了你的问题。
=
“第一” 按索引顺序排列为第一。
因此,“Megalopolis” 的排序低于 “Midland”,后者低于 “Smallville”
如果我用索引 “Aardvark” 创建了一行,它将首先出现。
索引不是添加数据的顺序,而是varchar值排序的顺序。
你给了我们你的代码-太好了。但是你需要给我们举一个例子,说明你在哪里遇到了你的问题。
=
“第一” 按索引顺序排列为第一。
因此,“Megalopolis” 的排序低于 “Midland”,后者低于 “Smallville”
如果我用索引 “Aardvark” 创建了一行,它将首先出现。
索引不是添加数据的顺序,而是varchar值排序的顺序。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




