來源於:http://blog.csdn.net/ceclar123/article/details/7974973
傳統的fetch into一次只能取得一條數據,使用fetch bulk collect into可以一次從游標中取得所有數據,使用limit子句可以限制一次取的數據條數
1、fetch bulk collect into
- begin
- declare
- cursor c_dept is select * from dept;
- type dept_record is table of dept%rowtype;
- v_dept dept_record;
- begin
- open c_dept;
- fetch c_dept bulk collect into v_dept;
- close c_dept;
- for i in 1.. v_dept.count loop
- dbms_output.put_line('部門名稱:'||v_dept(i).dname||' 部門地址:'||v_dept(i).loc);
- end loop;
- end;
- end;
2、使用limit子句限制提取的行數
- begin
- declare
- cursor c_dept is select * from dept;
- type dept_record is table of dept%rowtype;
- v_dept dept_record;
- begin
- open c_dept;
- loop
- exit when c_dept%NOTFOUND;
- fetch c_dept bulk collect into v_dept limit 3;
- dbms_output.put_line('-----------------------------------------------------------');
- for i in 1.. v_dept.count loop
- dbms_output.put_line('部門名稱:'||v_dept(i).dname||' 部門地址:'||v_dept(i).loc);
- end loop;
- end loop;
- close c_dept;
- end;
- end;