mysql 自定义函数,生成 n 个字符长度的随机字符串
-- sql function
delimiter $$
create function rand_str(n int) returns VARCHAR(255)
BEGIN
declare str VARCHAR(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSQUVWXYZ';
declare i int DEFAULT 0;
declare res_str VARCHAR(255) default '';
while i < n do
set res_str = concat(res_str,substr(str,FLOOR(rand()*52+1),1));
set i = i + 1;
end while;
return res_str;
end$$
delimiter ;-- sql function