On May 7, 6:51 am, m...@pixar.com wrote:
> This is what I'm doing now... is there a better way?
> It would be great if there were some construct such
> as 'for i in x begin ... end;'
>
> i := x.first;
> loop
> dbms_output.put_line(i);
> exit when i = x.last;
> i := x.next(i);
> end loop;
>
> Many TIA!
> Mark
This will break for empty collections. You can do
SQL> set serverout on
SQL> DECLARE TYPE population_type IS TABLE OF NUMBER INDEX BY
VARCHAR2(64);
2 continent_population population_type;
3 which VARCHAR2(64);
4 BEGIN
5 dbms_output.put_line('-----------');
6
7 which := continent_population.FIRST;
8 while which is not null loop
9 dbms_output.put_line(which || ' -> ' ||
continent_population(which));
10 which := continent_population.NEXT(which);
11 end loop;
12
13 dbms_output.put_line('-----------');
14
15 continent_population('Australia') := 30000000;
16 continent_population('Antarctica') := 1000; -- Creates new
entry
17 continent_population('Antarctica') := 1001; -- Replaces
previous value
18
19 which := continent_population.FIRST;
20 while which is not null loop
21 dbms_output.put_line(which || ' -> ' ||
continent_population(which));
22 which := continent_population.NEXT(which);
23 end loop;
24
25 dbms_output.put_line('-----------');
26 END;
27 /
-----------
-----------
Antarctica -> 1001
Australia -> 30000000
-----------
PL/SQL procedure successfully completed.
SQL>
Cheers
robert
see
http://download.oracle.com/docs/cd/B...htm#sthref1022 http://download.oracle.com/docs/cd/B...htm#sthref1146