MySQL 随机密码生成代码

数据库评论499字数 140阅读模式

晚上有朋友问起,简单的写了一个。

  1. DELIMITER $$
  2. CREATE
  3. FUNCTION `t_girl` . `func_rand_string` ( f_num tinyint unsigned , f_type tinyint unsigned )
  4. RETURNS varchar ( 32)
  5. BEGIN
  6. -- Translate the number to letter.
  7. -- No 1 stands for string only.
  8. -- No 2 stands for number only.
  9. -- No 3 stands for combination of the above.
  10. declare i int unsigned default 0;
  11. declare v_result varchar ( 255) default '' ;
  12. while i < f_num do
  13. if f_type = 1 then
  14. set v_result = concat ( v_result, char ( 97+ ceil( rand ( ) * 25) ) ) ;
  15. elseif f_type= 2 then
  16. set v_result = concat ( v_result, char ( 48+ ceil( rand ( ) * 9) ) ) ;
  17. elseif f_type= 3 then
  18. set v_result = concat ( v_result, substring ( replace ( uuid ( ) , '-' , '' ) , i+ 1, 1) ) ;
  19. end if;
  20. set i = i + 1;
  21. end while;
  22. return v_result;
  23. END $ $
  24. DELIMITER ;

调用方法示例:很文博客-https://www.zhenjiekeji.com/50333.html

  1. select func_rand_string(12,3);
很文博客-https://www.zhenjiekeji.com/50333.html很文博客-https://www.zhenjiekeji.com/50333.html
weinxin
我的微信
微信号已复制
扫一扫更精彩
大家的支持是我更新的动力!!!
匿名

发表评论

匿名网友