Is it possible to insert more than one row in a table with one insert statement? I know this will happen if I do:
是否可以使用一个insert语句在表中插入多行?我知道如果我这样做会发生:
insert into table ( fields ) select values from another_table
But what if I want to insert:
但是如果我想插入怎么办:
row 1 - ( a1, b1, c1 )
row 2 - ( a2, b2, c2 )
...
row n - ( an, bn, cn )
with just one insert command?
只有一个插入命令?
4 个解决方案
#1
7
Two solutions (source : http://appsfr.free.fr/spip.php?article21 ):
两种解决方案(来源:http://appsfr.free.fr/spip.php?article21):
INSERT ALL
INTO table (column1, column2)
VALUES (value1, value2)
INTO table (column1, column2)
VALUES (value1, value2)
...etc...
SELECT * FROM DUAL ;
or
要么
INSERT INTO table (column1, column2)
SELECT value1, value2 FROM DUAL UNION ALL
SELECT value1, value2 FROM DUAL UNION ALL
...etc...
SELECT value1, value2 FROM DUAL ;
#2
5
全部插入
INSERT ALL
INTO mytable (column1, column2, column3) VALUES ('val1.1', 'val1.2', 'val1.3')
INTO mytable (column1, column2, column3) VALUES ('val2.1', 'val2.2', 'val2.3')
INTO mytable (column1, column2, column3) VALUES ('val3.1', 'val3.2', 'val3.3')
SELECT * FROM dual;
#3
3
INSERT INTO products (product_no, name, price) VALUES
(1, 'Cheese', 9.99),
(2, 'Bread', 1.99),
(3, 'Milk', 2.99);
#4
-5
No, this is not possible. As you already stated yourself, it is only possible with a select clause providing the insert values and rows.
不,这是不可能的。正如您已经说过的那样,只有使用select子句提供插入值和行才能实现。
#1
7
Two solutions (source : http://appsfr.free.fr/spip.php?article21 ):
两种解决方案(来源:http://appsfr.free.fr/spip.php?article21):
INSERT ALL
INTO table (column1, column2)
VALUES (value1, value2)
INTO table (column1, column2)
VALUES (value1, value2)
...etc...
SELECT * FROM DUAL ;
or
要么
INSERT INTO table (column1, column2)
SELECT value1, value2 FROM DUAL UNION ALL
SELECT value1, value2 FROM DUAL UNION ALL
...etc...
SELECT value1, value2 FROM DUAL ;
#2
5
全部插入
INSERT ALL
INTO mytable (column1, column2, column3) VALUES ('val1.1', 'val1.2', 'val1.3')
INTO mytable (column1, column2, column3) VALUES ('val2.1', 'val2.2', 'val2.3')
INTO mytable (column1, column2, column3) VALUES ('val3.1', 'val3.2', 'val3.3')
SELECT * FROM dual;
#3
3
INSERT INTO products (product_no, name, price) VALUES
(1, 'Cheese', 9.99),
(2, 'Bread', 1.99),
(3, 'Milk', 2.99);
#4
-5
No, this is not possible. As you already stated yourself, it is only possible with a select clause providing the insert values and rows.
不,这是不可能的。正如您已经说过的那样,只有使用select子句提供插入值和行才能实现。