Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How do I insert data into a table in bulk?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report