--table of--index by 元素引用测试
set serveroutput on
declare
type table_type is table of number index by binary_integer;
table1 table_type;
begin
table1(1):=1;
table1(2):=2;
table1(3):=3;
dbms_output.put_line(table1(1));
dbms_output.put_line(table1(2));
dbms_output.put_line(table1(3));
end;
/
1
2
3
PL/SQL procedure successfully completed.
SQL>
--测试index by 且table of 类型之count,next,prior,first,last,exists用法
SQL> declare
2 type table_type is table of number index by binary_integer;
3 table1 table_type;
4 begin
5 table1(1):=1;--为第1个slot提供值1
6 table1(4):=4;--为第2个slot提供值4
7 dbms_output.put_line(table1.count);--count表示共占用几个slot,未分配指定值的slot不会计数 --
8 for i in table1.first..table1.last loop --用first及last表示第1个及最后1个slot对应的值
9 if table1.exists(i) then --用exists判断对应slot是否分配指定了值,避免触发异常no_data_found
10 dbms_output.put_line(table1(i));
11 else
12 dbms_output.put_line('no data in slot '||i);--用else触发异常
13 end if;
14 end loop;
15 dbms_output.put_line(table1.prior(1));--prior表示上1个slot对应的值
16 dbms_output.put_line(table1.next(0));--同上,下1个slot对应的值
17 dbms_output.put_line(table1(4));
18 dbms_output.put_line(table1.prior(5)); --delete 删除slot对应的值并释放内存
19 dbms_output.put_line(table1.next(4));--返回的值为null
20 end;
21 /
2
1
no data in slot 2
no data in slot 3
4
1
4
4
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-671025/ ,如需转载,请注明出处,否则将追究法律责任。