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;  
  • 相关阅读:
    【python-leetcode142-快慢指针】环形链表2
    SpringMvc 拦截器
    什么是RESTful?RESTfule风格
    Http协议
    SpringMVC Mock测试
    Oracle 创建用户,赋予指定表名/视图只读权限
    添加junit和spring-test还是用不了@Test和@RunWith(SpringJUnit4ClassRunner.class)注解
    SpringMVC 数据交互
    SpringMvc commons-fileupload图片/文件上传
    SpringMvc 异常处理器
  • 原文地址:https://www.cnblogs.com/ys-wuhan/p/6007698.html
Copyright © 2011-2022 走看看