zoukankan      html  css  js  c++  java
  • 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;  
  • 相关阅读:
    别再重复造轮子了,利用list创建任意数据类型的链表
    可配置内存池实现
    简单内存池实现
    基于本博客版本中的循环缓冲的测试(Linux环境)
    循环缓冲实现(ring buffer/circular buffer)
    recvfrom超时设置
    Linux系统如何做性能测试?
    深入理解虚拟内存机制
    Linux 内核的测试和调试
    python学习之路 实现简单的计算机功能。
  • 原文地址:https://www.cnblogs.com/ys-wuhan/p/6007698.html
Copyright © 2011-2022 走看看