Oracle Batch data extraction from Cursors ____oracle

Source: Internet
Author: User

The traditional fetch into only one data at a time, using the fetch bulk collect into can get all the data from the cursor at once, use the limit clause to limit the number of data bars taken at a time

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 (' Department Name: ' | | V_dept (i). dname| | '   Department Address: ' | | V_dept (i). Loc);     
    End Loop;
  End;
End


2, using the limit clause to limit the number of rows fetched

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 (' Department Name: ' | | V_dept (i). dname| | '   Department Address: ' | | V_dept (i). Loc);     
        End Loop;
    End Loop;
    Close c_dept;
  End;
End


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.