oracle index-by table的遍历

来源:互联网 发布:java 1.7.0 openjdk 编辑:程序博客网 时间:2024/06/04 13:42

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;


 

原创粉丝点击