Home >Database >Mysql Tutorial >MySQL与MSSQl使用While语句循环生成测试数据的代码_MySQL

MySQL与MSSQl使用While语句循环生成测试数据的代码_MySQL

WBOY
WBOYOriginal
2016-06-01 13:20:38740browse

bitsCN.com 在MySQL中,使用While语句循环与SQL Server中有所不同,代码测试通过。

MSSQL中使用while语句循环生成数据的方法:

示例代码:

declare @a int
set @a = 1
while @abegin
INSERT INTO demotable (id,item1,item2) VALUES (@a,"abc","123")
set @a = @a + 1
end

MySQL中,使用while循环处理数据方法:需要新建为存储过程,直接调用执行存储过程。

示例代码:

CREATE DEFINER=`root`@`localhost` PROCEDURE `NewProcedure`()
BEGIN
DECLARE i INT;
SET i=1;
WHILE iINSERT INTO demotable (id,item1,item2) VALUES (i,"测试试题","0");
SET i = i + 1;
END WHILE;
END;
bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn