当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL 随机密码生成代码

MySQL 随机密码生成代码

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

delimiter $$

create
function `t_girl` . `func_rand_string` ( f_num tinyint unsigned , f_type tinyint unsigned )
returns varchar ( 32)
begin
-- translate the number to letter.
-- no 1 stands for string only.
-- no 2 stands for number only.
-- no 3 stands for combination of the above.
declare i int unsigned default 0;
declare v_result varchar ( 255) default '' ;
while i < f_num do
if f_type = 1 then
set v_result = concat ( v_result, char ( 97+ ceil( rand ( ) * 25) ) ) ;
elseif f_type= 2 then
set v_result = concat ( v_result, char ( 48+ ceil( rand ( ) * 9) ) ) ;
elseif f_type= 3 then
set v_result = concat ( v_result, substring ( replace ( uuid ( ) , '-' , '' ) , i+ 1, 1) ) ;
end if;
set i = i + 1;
end while;
return v_result;

end $ $

delimiter ;

调用方法示例:
复制代码 代码如下:

select func_rand_string(12,3);

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网