当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql 动态生成测试数据

mysql 动态生成测试数据

2017年12月12日  | 移动技术网IT编程  | 我要评论
一、问题 要生成两类数据: a类:两位的 01 02 03 。。。09 10 11。。。19 20 21 。。。98 99 另一类b类:三位的 100 101 102 。。
一、问题
要生成两类数据:
a类:两位的 01 02 03 。。。09 10 11。。。19 20 21 。。。98 99
另一类b类:三位的 100 101 102 。。。110 111 112。。。998 999
二、解决办法
1、建表
复制代码 代码如下:

create table `test`.`ta` (
`a` varchar(45) not null
) engine=innodb default charset=utf8;

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;

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网