oracle從游標批量提取數據


來源於:http://blog.csdn.net/ceclar123/article/details/7974973

 

傳統的fetch into一次只能取得一條數據,使用fetch bulk collect into可以一次從游標中取得所有數據,使用limit子句可以限制一次取的數據條數

1、fetch bulk collect into


 
  1. begin  
  2.   declare     
  3.     cursor c_dept is select * from dept;  
  4.     type dept_record is table of dept%rowtype;  
  5.     v_dept dept_record;  
  6.   begin  
  7.     open c_dept;  
  8.     fetch c_dept bulk collect into v_dept;  
  9.     close c_dept;  
  10.     for i in 1.. v_dept.count loop  
  11.         dbms_output.put_line('部門名稱:'||v_dept(i).dname||'   部門地址:'||v_dept(i).loc);       
  12.     end loop;  
  13.   end;  
  14. end;  


2、使用limit子句限制提取的行數


 
    1. begin  
    2.   declare     
    3.     cursor c_dept is select * from dept;  
    4.     type dept_record is table of dept%rowtype;  
    5.     v_dept dept_record;  
    6.   begin  
    7.     open c_dept;  
    8.     loop  
    9.       exit when c_dept%NOTFOUND;  
    10.       fetch c_dept bulk collect into v_dept limit 3;    
    11.       dbms_output.put_line('-----------------------------------------------------------');     
    12.         for i in 1.. v_dept.count loop  
    13.             dbms_output.put_line('部門名稱:'||v_dept(i).dname||'   部門地址:'||v_dept(i).loc);       
    14.         end loop;  
    15.     end loop;  
    16.     close c_dept;  
    17.   end;  
    18. end;  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM