场景:对于收款员结账会出现组合付款的现象,在一些报表中需要在一行中体现所有的付款方式.
问题:传统的方法是用一个函数使用个游标咣咣一顿循环,组合一个结果给反回来.不用不知道呀,这东西效率相当差.差到不能忍受为止.
解决办法:网上学来的原文(http://www.itpub.net/viewthread.php?tid=837409).
SQL> declare
2 type t_type is table of dept%rowtype index by binary_integer;
3 myRecord t_type;
4 begin
5 select * bulk collect into myRecord from dept;
6 for i in myRecord.first..myRecord.last loop
7 dbms_output.put_line(myRecord(i).deptno || ' ' || myRecord(i).dname);
8 end loop;
9 end;
10 /
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
PL/SQL procedure successfully completed