Updating two tables

Using the same key with a different value changes the value.Example 5-1 declares an associative array that is indexed by a string, populates it, and prints it.

To access an element of a varray, you use standard subscripting syntax.

Figure 5-2 shows a varray named Nested tables and associative arrays differ in persistence and ease of parameter passing.

A nested table can be stored in a database column; therefore, you can use a nested table to simplify SQL operations in which you join a single-column table with a larger table.

DECLARE 2 -- Associative array indexed by string: 3 4 TYPE population IS TABLE OF NUMBER -- Associative array type 5 INDEX BY VARCHAR2(64); 6 7 city_population population; -- Associative array variable 8 i VARCHAR2(64); 9 10 BEGIN 11 -- Add new elements to associative array: 12 13 city_population('Smallville') := 2000; 14 city_population('Midland') := 750000; 15 city_population('Megalopolis') := 1000000; 16 17 -- Change value associated with key 'Smallville': 18 19 city_population('Smallville') := 2001; 20 21 -- Print associative array: 22 23 i := city_population.

FIRST; 24 25 WHILE i IS NOT NULL LOOP 26 DBMS_Output.