#数据表的结构为Data_DT ,ACNO,Product_Code,CYNO,BRNO,LABL,MSUM_P,QSUM_P,HSUM_P,YSUM_P,MSUM_N,QSUM_N,HSUM_N,YSUM_N,Field1,Field2,Field3 use property; drop procedure if exists insertt;#假如存在储存过程则删除 delimiter $$ CREATE procedure insertt() #创建一个储存过程 begin set @a=1; #学号 set @b=1; set @c=1; while @a<100000001 do #假如@a<2000010001则返回true,继续执行 set @d=rand_string(5); #姓名,随即赋值,值为5位a-zA-Z的任意组合 set @e=rand_string(5); set @f=rand_sex(1); set @g=rand_sex(1); set @h=rand_sex(1); set @i=rand_sex(1); set @j=rand_sex(1); set @k=rand_sex(1); set @l=rand_sex(1); set @m=rand_sex(1); set @n=rand_sex(1); set @o=rand_string(5); set @p=rand_string(5); set @q=rand_string(5); insert into tbIf_Acct_BL_Inner values(@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n,@o,@p,@q); set @a=@a+1; set @b=@b+1; set @c=@c+1; end while; end$$ delimiter ; #执行存储过程插入数据 call insertt() ; #创建一个随机产生字符串的函数 set global log_bin_trust_function_creators = 1; DROP FUNCTION IF EXISTS rand_string; DELIMITER // CREATE FUNCTION rand_string(n INT) RETURNS VARCHAR(255) BEGIN DECLARE chars_str varchar(100) DEFAULT "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; DECLARE return_str varchar(255) DEFAULT ""; DECLARE i INT DEFAULT 0; WHILE i < n DO SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*52 ),1));#52代表在52个字母中随即找出一个 SET i = i +1; END WHILE; RETURN return_str; END // delimiter ; #创建一个随机产生字符串的函数,0和1随机出现 set global log_bin_trust_function_creators = 1; DROP FUNCTION IF EXISTS rand_sex; DELIMITER // CREATE FUNCTION rand_sex(n INT) RETURNS VARCHAR(255) BEGIN DECLARE chars_str varchar(100) DEFAULT "01"; DECLARE return_str varchar(255) DEFAULT ""; DECLARE i INT DEFAULT 0; WHILE i < n DO SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*2 ),1)); SET i = i +1; END WHILE; RETURN return_str; END // delimiter ;
解决方案
40
将create function放到create procedure前面