mysql 动态生成测试数据的语句

很文博客hinven.com 数据库评论179字数 639阅读模式
广告也精彩

mysql 动态生成测试数据的语句,方便测试数据。

一、问题文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/50765.html

要生成两类数据:文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/50765.html

A类:两位的 01 02 03 。。。09 10 11。。。19 20 21 。。。98 99文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/50765.html

另一类B类:三位的 100 101 102 。。。110 111 112。。。998 999文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/50765.html

二、解决办法文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/50765.html

1、建表文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/50765.html

CREATE TABLE `test`.`ta` (
`a` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/50765.html

2、创建存储过程

DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`proc_tp` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_tp`(in prex int,in max int)
begin
declare i INT DEFAULT 0;
declare s varchar(500);
WHILE (i<10 and prex<max) DO
select concat(prex,i) into s;
insert into ta (a) values (s);
set i=i+1;
if(i=10 and prex<max) then
set prex=prex+1;
set i=0;
end if;
END WHILE ;
end $$
DELIMITER ;

3、分别调用执行存储过程

CALL proc_tp(0,10) 创建A类数据

CALL proc_tp(10,100) 创建B类数据

4、查询结果

SELECT * FROM ta t order by cast(a as signed) asc;

工具:作品在线观看

女优:最新作品观看

中文:国语在线观看

weinxin
我的微信
扫一扫更精彩
大家的支持是我更新的动力!!!
 
广告也精彩
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证