Oracle/MySQL通过存储过程批量插入百万数据
Oracle:
create sequence s start with 1; //设置下标起始值为1 方便Insert中递增
begin
for i in 1..260000 loop //260000代表循环次数 数据量
${Insert语句,记得带分号,需要递增的值使用s.nextval}
end loop;
commit;
end;
粘贴记得把上述注释去掉,根据业务定sequence值与循环次数
MySQL:
drop PROCEDURE if exists test_insert; delimiter // CREATE PROCEDURE test_insert(n int) begin declare v int default 1; SET AUTOCOMMIT=0; while v <= n do ${Insert语句,记得带分号,需要从1开始递增的值用v代替} set v = v + 1; end while; SET AUTOCOMMIT=1; end // call test_insert(1000000)
注意上面delimiter和end后面的//不能去掉,代表分隔,去掉要报错,替换${} 插入语句即可

浙公网安备 33010602011771号