December 2010
Intermediate to advanced
451 pages
11h 16m
English
You need a routine to display sales totaled by region, which is stored in a collection of numbers, but the collection is indexed by a character string. Using a LOOP from 1 to the maximum size will not work.
Use the FIRST and LAST method to traverse the collection allowing PL/SQL to supply the proper index values. In this example, sales amounts are stored in a TABLE indexed by a string.
DECLARE
TYPE ntype IS TABLE OF NUMBER INDEX BY VARCHAR2(5);
nlist ntype;
idx VARCHAR2(5);
total integer := 0;
BEGIN
nlist('North') := 100;
nlist('South') := 125;
nlist('East') := 75;
nlist('West') := 75;
idx := nlist.FIRST;
LOOP
EXIT WHEN idx is null; DBMS_OUTPUT.PUT_LINE ...Read now
Unlock full access