The SQL statement of Cursor batch fetch is realized by using bulk collect in Oracle _oracle

Source: Internet
Author: User
In general, there is not much chance of using bulk fetch, but Oracle provides this functionality we'd better get familiar with it and maybe when it will be used.


Copy Code code as follows:

Declare
Cursor C1 is select * from T_depart;
V_depart T_depart%rowtype;
Type V_code_type is table of T_depart.depart_code%type;
V_code V_code_type;
Type V_name_type is table of T_depart.depart_name%type;
V_name V_name_type;
Begin
Open C1;
Fetch C1 Bulk collect into V_code, v_name;
For I in 1..v_code.count loop
Dbms_output.put_line (V_code (i) | | ' '|| V_name (i));
End Loop;
Close C1;
End

Through the above, you can find that if a lot of columns, to define a set for each column seems to be a bit cumbersome, you can combine the collection and%rowtype together to use simplified procedures!
Copy Code code as follows:

Declare
Cursor C1 is select * from T_depart;
Type V_depart_type is table of T_depart%rowtype;
V_depart V_depart_type;
Begin
Open C1;
Fetch C1 bulk collect into V_depart;
For I in 1..v_depart.count loop
Dbms_output.put_line (V_depart (i) depart_code| | ' '||
V_depart (i). Depart_name);
End Loop;
Close C1;
End

You can use the Count property of the collection when you output the results, and you can use the%rowtype type's content when referencing the contents of the V_depart (i). Depart_code, not V_depart.depart_ Code (i), of course, has no such wording, even if the meaning is not the same.
Copy Code code as follows:

Declare
Cursor C1 is select * from T_depart;
Type V_depart_type is table of T_depart%rowtype;
V_depart V_depart_type;
Begin
Open C1;
Fetch C1 bulk collect into V_depart;
For I in V_depart.first. V_depart.last Loop
Dbms_output.put_line (V_depart (i) depart_code| | ' '||
V_depart (i). Depart_name);
End Loop;
Close C1;
End

Related Article

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.