mysql
方案一:带列名
INSERT INTO example
(example_id, name, value, other_value)
VALUES
(100, 'Name 1', 'Value 1', 'Other 1'),
(101, 'Name 2', 'Value 2', 'Other 2'),
(102, 'Name 3', 'Value 3', 'Other 3'),
(103, 'Name 4', 'Value 4', 'Other 4');
方案二:不带列名
INSERT INTO example
VALUES
(100, 'Name 1', 'Value 1', 'Other 1'),
(101, 'Name 2', 'Value 2', 'Other 2'),
(102, 'Name 3', 'Value 3', 'Other 3'),
(103, 'Name 4', 'Value 4', 'Other 4');
oracle
方案一:insert all 实现
INSERT ALL
INTO A(field_1,field_2) VALUES (value_1,value_2)
INTO A(field_1,field_2) VALUES (value_3,value_4)
INTO A(field_1,field_2) VALUES (value_5,value_6)
SELECT 1 FROM DUAL;
方案二:union all实现
INSERT INTO ACCOUNT_INFO
(ID, USERNAME, PASSWORD, GENDER)
(select ‘1’,'jack','1234','男' from dual
union all select ‘2’,'lisi','1234','男'from dual
union all select ...)
本文详细介绍在MySQL和Oracle数据库中批量插入数据的两种有效方法。在MySQL中,可通过带列名或不带列名的方式进行插入;而在Oracle中,则可使用insert all或union all实现。这些方法能显著提高数据插入效率,适用于大数据量的场景。
1581

被折叠的 条评论
为什么被折叠?



