Code Listing 1: Example of string-based indexing
1 DECLARE
2 TYPE population_type IS TABLE OF NUMBER INDEX BY VARCHAR2(64);
3 country_population population_type;
4 continent_population population_type;
5 howmany NUMBER;
6 limit VARCHAR2(64);
7 BEGIN
8 country_population('Greenland') := 100000;
9 country_population('Iceland') := 750000;
10
11 howmany := country_population('Greenland');
12
13 continent_population('Australia') := 30000000;
14
15 continent_population('Antarctica') := 1000; -- Creates new entry
16 continent_population('Antarctica') := 1001; -- Replaces previous value
17
18 limit := continent_population.FIRST;
19 DBMS_OUTPUT.PUT_LINE (limit);
20 DBMS_OUTPUT.PUT_LINE (continent_population(limit));
21
22 limit := continent_population.LAST;
23 DBMS_OUTPUT.PUT_LINE (limit);
24 DBMS_OUTPUT.PUT_LINE (continent_population(limit));
25 END;
Antarctica
1001
Australia
30000000
|