ITPub博客

首页 > IT职业 > IT职场 > MySQL 随机密码生成代码

MySQL 随机密码生成代码

IT职场 作者:jhere 时间:2021-09-09 09:29:36 0 删除 编辑

           复制代码 代码如下:
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 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);
                       

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4022/viewspace-2803695/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: JS模块化
请登录后发表评论 登录
全部评论

注册时间:2019-10-17

  • 博文量
    81
  • 访问量
    655