1.创建个测试表
create table tb1(
id int primary key auto_increment,
num int
)engine=innodb charset=utf8 //
2.存储过程循环插入数据
-- loop 循环
DELIMITER //
CREATE PROCEDURE IF EXISTS p3//
CREATE PROCEDURE p3(IN n INT)
BEGIN
DECLARE i INT DEFAULT 0;
SET i = 0;
lp : LOOP
INSERT INTO tb1(num) VALUES(i+1);
SET i = i +1;
IF i = n THEN LEAVE lp;
END IF;
END LOOP;
END//
CALL p3(100);
SELECT * FROM tb1;