最新消息: 新版网站上线了!!!

mysql存储过程(1)随机增加10万数据

CREATE PROCEDURE p_test(pa int(11))

BEGIN

declare max_num int(11) default 100000;

declare i int default 0;

declare rand_num int;


select count(id) into max_num from test_test; #查询id总数,查询结果存入变量max_num


while i<pa DO

if max_num < 100000 THEN

select cast(rand()*100 as unsigned) into rand_num;

insert into test_test(num)values(rand_num);

end if;

set i = i+1;

end while;

end


调用:

call p_test(100000);


.....

转载请注明:谷谷点程序 » mysql存储过程(1)随机增加10万数据