PL/SQL中使用嵌套表、变长数组(Varray)注意事项

来源:互联网 发布:mac php集成环境 编辑:程序博客网 时间:2024/06/15 21:47
1.当使用嵌套表元素时,必须首先使用其构造方法初始化嵌套表,用来固定它的长度。
2.变长数组(Varray)和嵌套表一样,只不过变长数组的构造函数初始化长度有一定的范围限制,而嵌套表初始化长度时无范围,他们都可以作为表列的数据类型使用。
3.由于嵌套表的元素值可以是稀疏的,所以删除的时候元素值别删掉,而元素位置还在,可以为该元素下标位置重新赋值,删除其中一个时用循环会报错是因为元素位置还在,但元素值不在,除非重新赋值。例如:
 declare type dept_table_type is table of scott.dept.dname%type;    dept_table dept_table_type:=dept_table_type(null,null,null,null); begin   select dname into dept_table(1) from scott.dept where deptno=10;   select dname into dept_table(2) from scott.dept where deptno=20;   select dname into dept_table(3) from scott.dept where deptno=30;  select dname into dept_table(4) from scott.dept where deptno=40;  dept_table.delete(3);  dbms_output.put_line(dept_table.count);count=3。   for i in 1..dept_table.count loop dbms_output.put_line(dept_table(i));  end loop; end;



原创粉丝点击