SQL> set serveroutput on
SQL> r
1 declare
2 type mytable is table of dept%rowtype;--此类型定义用到table of且rowtype,为表的部分记录集,而非某特定的行
3 l_mydata mytable;
4 l_refc sys_refcursor; --定义一个refcursor
5 begin
6 open l_refc for select deptno,dname,loc from dept;--打开以上定义的refcursor
7 fetch l_refc bulk collect into l_mydata;--利用fetch选项bulk collect into把refcursor结果集提取到或传递到l_mydata变量(类型为以上定义的table of rowtype)
8 close l_refc;--提取refcursor游标完事,关闭它吧,别占用资源
9 for i in 1..l_mydata.count loop --这里用了for,count,loop(注:加了个count)
10 dbms_output.put_line(l_mydata(i).deptno||' '||l_mydata --显示每个具体的值用 (i)
(i).dname||' '||l_mydata(i).loc);
11 end loop;
12* end;
10 ACCOUNTING NEW YORK ##把表dept记录全显示出来了
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
PL/SQL procedure successfully completed.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-670464/ ,如需转载,请注明出处,否则将追究法律责任。