创建测试表
CREATE TABLE tb1(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,num INT
)ENGINE=INNODB CHARSET=utf8
-- while循环
DELIMITER //
CREATE PROCEDURE IF EXISTS p1 //
CREATE PROCEDURE p2(IN n INT)
BEGIN
DECLARE i INT DEFAULT 0;
WHILE i < n DO
INSERT INTO tb1(num) VALUES (i+1);
SET i=i+1;
END WHILE;
END//
CALL p2(10); 调用存储过程 插入10条数据
SELECT * FROM tb1; 查询