How do I insert data into a table in bulk?
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!