这个是网友++C++在群里问的一个关于MySQL的问题,本篇文章实验测试环境为MySQL 5.6.20,事务隔离级别为REPEATABLE-READ ,在演示问题前,我们先准备测试环境。准备一个测试表test以及一个存储过程循环往test表里面插入记录。

 

CREATE TABLE test
(
  `id` int(11) primary key not null,
  `name` char(255) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 
 
delimiter &&
drop procedure if exists prc_insert;
 
create procedure prc_insert(in  cnt int)
begin
declare i int;
set i=1;
while i < cnt do
    insert into test(id, name) select i,  CONCAT('name',i) from dual;
    
    set i = i+1;
 
end while;
end &&
 
delimiter ;

相关文章: