Oracle-by-article vs. Bulk Insert Data Mode comparison

Source: Internet
Author: User
Tags bulk insert

Create a test table

CREATE TABLE Base_users

(

UserID VARCHAR2 (16),

Username VARCHAR2 (32),

passwd VARCHAR2 (16)

) Tablespace Cat_data;

In an insert-by-line way

Create or replace procedure Insert_data_one_by_one (n in number)

As

CurrentID Number (16): = 0;

L_userid VARCHAR2 (16);

L_username VARCHAR2 (32);


SQLText VARCHAR2 (256);


Begin
Dbms_output.put_line (' Begin ... ' | | to_char (current_timestamp, ' HH24:MI:SSxFF '));

SQLText: = ' INSERT INTO Base_users (userid, username, passwd) VALUES (: UserID,: Username, ' | | ' 111111) ';


    loop
         Currentid:=currentid + 1;
        l_userid:= To_char (currentId);
        l_username:= to_char (18600000000 + CurrentID);

Execute immediate sqltext using L_userid, l_username;
Exit when CurrentID >= N;
End Loop;
Commit
Dbms_output.put_line (' End commit ... ' | | to_char (current_timestamp, ' HH24:MI:SSxFF '));
End Insert_data_one_by_one;
/

The way to use BULK INSERT

Create or replace procedure Insert_data_bulk (n in number)

As

I int;

Tmp_userid number;

Tmp_username number;

Type Useridarray is Table of VARCHAR2 (+) index by Binary_integer;

Type Usernamearray is Table of VARCHAR2 (+) index by Binary_integer;

Puserid Useridarray;

Pusername Usernamearray;

Begin

Dbms_output.put_line (' Begin ... ' | | to_char (current_timestamp, ' HH24:MI:SSxFF '));

Tmp_userid: = 1;

Tmp_username: = 18600000000;

For I in 1.. N Loop

Puserid (i): = Tmp_userid;

Pusername (i): = Tmp_username;

Tmp_userid: = Tmp_userid + 1;

Tmp_username: = tmp_username + 1;

End Loop;

ForAll i in 1.. N

INSERT INTO Base_users (userid, username, passwd)

VALUES (Puserid (i), pusername (i), ' 111111 ');

Commit

Dbms_output.put_line (' End ... ' | | to_char (current_timestamp, ' HH24:MI:SSxFF '));

Endinsert_data_bulk;

/

Test the insertion of 10 million data

Sql>set Serveroutput on

Sql>begin

Insert_data_one_by_one (10000000);

End

/

Begin ... 22:14:01.572928000
End commit ... 22:20:43.911104000

Sql>truncate table base_users;


Sql>begin

Insert_data_bulk (10000000);

End

/

Begin ... 22:25:31.497810000
End ... 22:27:23.801515000

Oracle-by-article vs. Bulk Insert Data Mode comparison

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.