日期:2014-05-16 浏览次数:20522 次
---使用数组将查询的记录存放到嵌套表中 declare type deptrecord is record ( deptno dept.deptno%type, dname dept.dname%type, loc dept.loc%type ); type number_array is table of deptrecord; number_collection number_array:=number_array(); begin number_collection.extend(5); dbms_output.put_line('number_collection的数量:'||number_collection.count); select * bulk collect into number_collection from dept; dbms_output.put_line('number_collection的数量:'||number_collection.count); for currow in number_collection.first .. number_collection.last loop dbms_output.put_line(number_collection(currow).deptno); end loop; end; ---使用数组将查询的记录存放到嵌套表中 declare type deptrecord is record( deptno dept.deptno%type, dname dept.dname%type, loc dept.loc%type); type number_array is table of deptrecord; number_collection number_array := number_array(); i number := 0; curroww number; begin for currow in (select * from dept) loop i := i + 1; number_collection.extend; number_collection(i).deptno := currow.deptno; number_collection(i).dname := currow.dname; number_collection(i).loc := currow.loc; end loop; for i in 1 .. number_collection.count loop dbms_output.put_line(''); dbms_output.put_line('循环方式一'); dbms_output.put_line('deptno:=' || number_collection(i).deptno); dbms_output.put_line('dname:=' || number_collection(i).dname); dbms_output.put_line('loc:=' || number_collection(i).loc); end loop; for i in number_collection.first .. number_collection.last loop dbms_output.put_line(''); dbms_output.put_line('循环方式二'); dbms_output.put_line('deptno:=' || number_collection(i).deptno); dbms_output.put_line('dname:=' || number_collection(i).dname); dbms_output.put_line('loc:=' || number_collection(i).loc); end loop; curroww := number_collection.first; loop exit when curroww is null; dbms_output.put_line(''); dbms_output.put_line('循环方式三'); dbms_output.put_line('deptno:=' || number_collection(i).deptno); dbms_output.put_line('dname:=' || number_collection(i).dname); dbms_output.put_line('loc:=' || number_collection(i).loc); curroww := number_collection.next(curroww); end loop; end;