1、打开navicat ,准备测试表,新建查询,输入以下语句,运行;
#创建测试表 DROP TABLE IF EXISTS test.test; CREATE TABLE test.test( id int(10) not null auto_increment, a int(10) not null, b int(10) not null, c int(10) not null, PRIMARY key (`id`) )ENGINE INNODB DEFAULT CHARSET utf8 COMMENT '测试表';
2、定义存储过程,新建查询,输入以下语句,运行;运行完之后,会在函数下看到该函数
#清空数据 TRUNCATE table test.test; #定义存储过程 delimiter // DROP PROCEDURE IF EXISTS insert_test_val; ##num_limit 要插入数据的数量,rand_limit 最大随机的数值 CREATE PROCEDURE insert_test_val(in num_limit int,in rand_limit int) BEGIN DECLARE i int default 1; DECLARE a int default 1; DECLARE b int default 1; DECLARE c int default 1; WHILE i<=num_limit do set a = FLOOR(rand()*rand_limit); set b = FLOOR(rand()*rand_limit); set c = FLOOR(rand()*rand_limit); INSERT into test.test values (null,a,b,c); set i = i + 1; END WHILE; END //
3、调用存储过程,新建查询,输入以下语句
call insert_test_val(100000,10);
4、结果