#产生随机字符串,用于测试数据库
drop procedure if exists randstr;
delimiter $$
create procedure randstr(num int(11)) #为了容易区分那个函数或者存储过程是那个数据库的,可以在函数名中加上数据库前缀test_randstr;
begin
declare str char(255) default 'q1we23r4t5y6u7i8o9p0asdfghjklzxcvbnm';
declare nums int(11);
declare returnstr char(255); #SQL变量名不能和列名一样
declare i int(11) default 0; #在声明变量时一定要在begin语句之后,除begin外的任何语句之前
select floor(truncate(rand(),1)*36)+1 into nums; #加1时为了防止产生随机数生成0的情况
select substring(str,nums,1) into returnstr;
#declare i int(11) default 0; #在声明变量时一定要在begin语句之后,除begin外的任何语句之前,像这个语句是不允许的
while i
select floor(truncate(rand(),1)*36)+1 into nums;
select concat(substring(str,nums,1),returnstr) into returnstr;
#set returnstr=concat(substring(str,nums,1),returnstr);
set i=i+1;
end while;
select returnstr as randstr;
end
$$
delimiter ;
call randstr(5);