Oracle中数组类型的几种用法

这里只讨论简单讨论一下Oracle中嵌套表数组的用法: 

declare
  type my_first_type is table of varchar2(20) index by binary_integer;
  l_test_type my_first_type;
  l_index number ;
begin
  for t_id_no in (select * from ls_appl) loop
    l_test_type(t_id_no.ls_appl_seq):=t_id_no.appl_loan_no;
  end loop;
 
  l_index := l_test_type.first;
  loop
    exit when l_index is null ;
    dbms_output.put_line(l_index ||' : ' ||l_test_type(l_index));
    l_index := l_test_type.next(l_index);
  end loop;
end;

上面的用法中声明一个varchar2类型的数组,其实of后面的只是一个数据类型。

我们用ls_appl表中的一个字段去填充它。

declare
  type my_type is table of loan%rowtype index by binary_integer;
  l_my_type my_type;
begin
  select * bulk collect into l_my_type from loan;
  for l_c in 1 .. l_my_type.count loop
    dbms_output.put_line(l_my_type(l_c).loan_no ||' : '||l_my_type(l_c).ctif_id_no);
  end loop;
end;

上面的用法有些时候可以用于替代cursor。

declare
  type my_record is record(hh number(15),nn varchar2(20));
  l_my_record my_record;
  type my_type is table of l_my_record%type index by binary_integer;
  l_my_type my_type;
begin
  select l.ls_appl_seq,l.appl_no bulk collect into l_my_type from ls_appl l;
  for i in 1 .. l_my_type.count loop
    dbms_output.put_line(l_my_type(i).hh || ' : ' ||l_my_type(i).nn);
  end loop;
end;

上面的用法中自己先定义了一个类型,然后又定义了该类型的数组。

 

参考:http://fxz-2008.iteye.com/blog/469766

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值