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

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;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值