表集合的extend属性
Extend 扩展元素的个数,且在使用下标时,只能到1到这个整个个数的范围:
CREATE or replace type list_of_name is table of varchar2(1000);
declare
happyfamily list_of_name:=list_of_name();--必须在使用的时候初始化,此处初始化为一个空元素,此处若不初始化,必须在体部初始化
children list_of_name:=list_of_name();
parents list_of_name:=list_of_name();
l_row BINARY_INTEGER;
begin
happyfamily.extend(5);--extend(4)是在最后一个元素后面增加4个元素
happyfamily(2):='a';
happyfamily(3):='b';
happyfamily(4):='c';
happyfamily(5):='d';
l_row:=happyfamily.first;
WHILE(l_row IS NOT NULL) LOOP
dbms_output.put_line('the name is :'||happyfamily(l_row));
l_row:=happyfamily.next(l_row);
END LOOP;
end;
结果:
the name is :
the name is :a
the name is :b
the name is :c
the name is :d
很显然,下标1没有,如果我们改一下:
CREATE or replace type list_of_name is table of varchar2(1000);
declare
happyfamily list_of_name:=list_of_name();--必须在使用的时候初始化,此处初始化为一个空元素,此处若不初始化,必须在体部初始化
children list_of_name:=list_of_name();
parents list_of_name:=list_of_name();
l_row BINARY_INTEGER;
begin
happyfamily.extend(5);--extend(4)是在最后一个元素后面增加4个元素
happyfamily(2):='a';
happyfamily(3):='b';
happyfamily(4):='c';
happyfamily(6):='d';
l_row:=happyfamily.first;
WHILE(l_row IS NOT NULL) LOOP
dbms_output.put_line('the name is :'||happyfamily(l_row));
l_row:=happyfamily.next(l_row);
END LOOP;
end;
结果:
很显然:extend所使用的下标值不能超过extend指定的值。