zoukankan      html  css  js  c++  java
  • 用MySQL 生成随机密码

    晚上有朋友问起,简单的写了一个。
    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);

  • 相关阅读:
    HDU1171(01背包均分问题)
    HDU2159(完全背包)
    HDU1203(01背包变形)
    DAG上的DP
    ADB命令小结
    HDU3065(AC自动机入门题)
    HDU2896(AC自动机入门题)
    性能测试监控分析(13)-sysstat安装升级
    tomcat(9)-linux apache tomcat集群环境搭建
    nginx(4)-负载均衡的5种策略及原理
  • 原文地址:https://www.cnblogs.com/secbook/p/2655285.html
Copyright © 2011-2022 走看看