ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL'
Statement processed.
DECLARE
-- Associative array indexed by string:
TYPE population IS TABLE OF NUMBER
INDEX BY VARCHAR2(64);
city_population population;
i VARCHAR2(64);
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;
Population of Megalopolis is 1000000
Population of Midland is 750000
Population of Smallville is 2001