记录表TABLE中 INDEX BY BINARY_INTEGER 的作用
type my_number_arr is table of number index by binary_integer;
其作用是,加了”index by binary_integer ”后,my_number_arr 类型的下标就是自增长,可以自动根据下标找到对应的值。my_number_arr 类型在插入元素时,不需要初始化,不需要每次extend增加一个空间。
而如果没有这句话“index by binary_integer”,那就得要显示对初始化,且每插入一个元素到numbers类型的table中时,都需要先extend。
示例:
1. 没加“index by binary_integer”时:
declare
type my_number_arr is table of number;
n my_number_arr := my_number_arr();
begin
n.extend;
n(1) := 2;
n.extend;
n(2) := 3;
for i in 1 .. n.count loop
dbms_output.put_line(n(i));
end loop;
end;
输出:2,3
2. 如果加了“index by binary_integer”,代码如下写就可以达到上面的效果:
declare
type my_number_arr is table of number index by binary_integer;
n my_number_arr;
begin
n(1) := 2;
n(2) := 3;
for i in 1 .. n.count loop
dbms_output.put_line(n(i));
end loop;
end;