Batch oracle operations

Source: Internet
Author: User


Oracle batch operation the following code is used for exercises when learning oracle. batch operation can solve the efficiency problem well: www.2cto.com Java code --- create table test2 (id number (6 ), name varchar2 (10) delete test2; select * from test2; ------ batch insert declare type id_table is table of number (6) index by binary_integer; type name_table is table of varchar2 (10) index by binary_integer; v_ids id_table; v_names name_table; starttime number (10); endtime number (10); begin starttime: = dbms_utility.get_time; for I in 1 .. 100000 loop v_ids (I): = I; v_names (I): = to_char (I) | 'hes'; end loop; /*************************************** * ********************************** it is not loop, instead, insert many records into the database forall I in 1 at a time .. the syntax of v_ids.count starts with forall index in .. end *************************************** * *********************************/forall I in 1.. v_ids.count insert into test2 (id, name) values (v_ids (I), v_names (I); endtime: = dbms_utility.get_time; dbms_output.put_line (endtime-starttime); end; ------ the batch result is 18 --- insert declare starttime number (10); endtime number (10); begin starttime: = dbms_utility.get_time; for I in 1 .. 100000 loop insert into test2 (id, name) values (I, to_char (I) | 'he '); end loop; endtime: = dbms_utility.get_time; dbms_output.put_line (endtime-starttime ); end; ---- the length of time is 262. In terms of time, the efficiency difference is at least 10 times www.2cto.com ---- another bulk collect operation) declare type test_table is table of test2 % rowtype index by binary_integer; v_testtable test_table; begin /************************************** ******************************. bulk collect Syntax :.......... bulk collect into collectName ************************************ * *****************************/select * bulk collect into v_testtable from test2; dbms_output.put_line (v_testtable.count); 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.