17,078
社区成员
发帖
与我相关
我的任务
分享
SQL>
SQL> declare
2 current varchar2(9 char);
3 element integer;
4 type months_varray is varray(12) of string(9 char);--
5 type calender_table is table of varchar2(9 char)--
6 index by varchar2(9 char);
7 month months_varray :=
8 months_varray('January','February','March','April'
9 ,'May','June','July','August','September'
10 ,'October','November','December');
11 calendar calender_table;
12 begin
13 if calendar.count=0 then
14 dbms_output.put_line('Assignment loop:');
15 dbms_output.put_line('----------------');
16 for i in month.first..month.last loop
17 calendar(month(i)) := to_char(i);
18 dbms_output.put_line('Index ['||month(i)||'] is ['||i||']');
19 end loop;
20 dbms_output.put(chr(10));
21 dbms_output.put_line('Post-assignment loop:');
22 dbms_output.put_line('----------------');
23 for i in 1..calendar.count loop
24 if i=1 then
25 current := calendar.first;
26 element := calendar(current);
27 else
28 if calendar.next(current) is not null then
29 current := calendar.next(current);
30 element := calendar(current);
31 else
32 exit;
33 end if;
34 end if;
35 dbms_output.put_line('Index ['||current||'] is ['||element||']');
36 end loop;
37 end if;
38 end;
39 /
PL/SQL procedure successfully completed
SQL> set serveroutput on;
SQL> /
Assignment loop:
----------------
Index [January] is [1]
Index [February] is [2]
Index [March] is [3]
Index [April] is [4]
Index [May] is [5]
Index [June] is [6]
Index [July] is [7]
Index [August] is [8]
Index [September] is [9]
Index [October] is [10]
Index [November] is [11]
Index [December] is [12]
Post-assignment loop:
----------------
Index [April] is [4]
Index [August] is [8]
Index [December] is [12]
Index [February] is [2]
Index [January] is [1]
Index [July] is [7]
Index [June] is [6]
Index [March] is [3]
Index [May] is [5]
Index [November] is [11]
Index [October] is [10]
Index [September] is [9]
PL/SQL procedure successfully completed
SQL>