Get the App
SLTechnology News&Howtos  ›  Database  › 

How do I insert data into a table in bulk?

Shulou Source: shulou.com Published: 2022-06-01 13:39:33 11月15日 Update

I'm sure oracle beginners will freak out when the leader says to insert thousands of pieces of data into a table. At that time, I inserted dozens of pieces of data into the table. I inserted them sentence by sentence. After dozens of executions, I was crazy. Later, I found that I could insert them in batches, saving a lot of time and energy.

Method 1: Use union all concatenation (this method is similar to inser into, but the execution speed is much faster)

insert into tmp(id,name,salary,address)

select ('001',' Zhang San','100',' Shanghai') from dual

union all

select ('002',' Li Si','200',' Chongqing') from dual

union all

select ('003',' Wangwu','300',' Beijing') from dual;

commit;

Method 2: Insert into... select... (It can be understood as data copying, inserting the data in tmp2 table into tmp1, and then adding where conditions)

insert into tmp1(id,name,salary,address)

select id,name,salary,address from tmp2

(where ...);

commit;

Method 3: Use insert all

insert all

into tmp(id,name,salary,address) values ('001 ',' Zhang San','100',' Shanghai')

into tmp(id,name,salary,address) values ('002 ',' Li Si','200',' Chongqing')

into tmp(id,name,salary,address) values ('003 ',' Wangwu','300',' Beijing')

select 1 from dual;

commit;

In addition, the method also supports inserting data into multiple tables:

insert all

into tmp1(id,name,salary,address) values ('001 ',' Zhang San','100',' Shanghai')

into tmp2(id,name,salary,address) values ('002 ',' Li Si','200',' Chongqing')

into tmp3(id,name,salary,address) values ('003 ',' Wangwu','300',' Beijing')

select 1 from dual;

commit;

Success, no longer because the leader let batch insertion data waste time and overtime!

In addition, we have any better way to welcome the message, we learn progress together! No overtime!

Tags: Data methods Zhang San Li Si Wang Wu Shanghai Beijing Chongqing time completed almost no beginners great achievements time conditions energy speed speed thousands of Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Huawei Apple MariaDB