How to insert multiple records at a time in Oracle

Oracle inserting multiple records at a time is very different from MYSQL. MYSQL   is like this, but it is  different in Oracle.

 

INSERT INTO Persons (LastName, Address) VALUES ('Wilson', 'Champs-Elysees'),('Gates', 'Champs-Elysees')

 

Oracle can use the virtual table dual to insert multiple records at a time. dual has a very strange "table" in Oracle. You can use this Dual to make a fuss.

 

First of all, do you know what the result of select '1' from dual is? By the way, the result is to return 1.

Second, you know

select '1' from dual
union all
select '2' from dual

 

What is the result? For birds, the result is 

 

1

2

 

So, here comes the most important part, 

 

insert into table name (field 1)
select '1' from dual
union all
select '2' from dual

 
So this time, two pieces of data are inserted. Of course, if the full field is inserted into that (field 1), it can be omitted.

Here's a concrete example:

 

insert into doc_data (code,id,value,state)
        select '13','Chuan A','Chengdu Public Security Bureau Traffic Police Detachment Vehicle Management Office',0 from dual
union all select '13','Chuan B','Mianyang Public Security Bureau Traffic Police Detachment Vehicle Management Office',0 from dual
union all select '13','Chuan C','Zigong Public Security Bureau Traffic Police Detachment Vehicle Management Office',0 from dual
union all select '13','Chuan D','Panzhihua Public Security Bureau Traffic Police Detachment Vehicle Management Office',0 from dual

 

Reference: Oracle uses virtual table dual to insert multiple records at once

 

Original link: http://woqilin.blogspot.com/2016/05/oracle.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326936237&siteId=291194637