您的位置:首页 > 数据库 > Oracle

Oracle中数组类型的几种用法

2011-07-13 16:36 781 查看
这里只讨论简单讨论一下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;
上面的用法中自己先定义了一个类型,然后又定义了该类型的数组。

参考:/article/4169885.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: