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

oracle index-by table的遍历

2013-08-07 13:44 357 查看
Oracle的数据集合类型,分三种:

Varray:固定长度(其他方法可扩展),连续的数组。对应其他程序中的数组。

Nested table:长度不固定,不连续。对应其他程序中的set,list等。

Associative Arrays(Known as index-by table):有索引的集合。对应其他程序中的hashMap。

前面的两种集合类型,遍历都比较简单,有很多种方法来遍历。最后一种,比较困惑人,看pl/sql的参考文档,更困惑人。问了几个同事,也都表示不知道。最后,摸索出来了,记在这里,备忘,也希望帮助更多人.....

declare
type tab_result is table of varchar2(20) index by varchar2(20);
vt_result tab_result;
which varchar2(20);
begin
vt_result('a'):='asd';
vt_result('u'):='lkj';
vt_result('e'):='hgj';
vt_result('i'):='uey';

--如何遍历?
which:=vt_result.first;
loop
dbms_output.put_line(which||'--->');
dbms_output.put_line(vt_result(which));

which:=vt_result.next(which);
exit when which is null;
end loop;
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: