Welcome 微信登录

首页 / 数据库 / MySQL / 用MySQL 生成随机密码

用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);Java实现MongoDB中自增长字段用MySQL 生成随机密码-增加大写处理相关资讯      MySQL数据库教程 
  • MySQL 处理非法数据  (04/09/2013 08:06:28)
  • MySQL关于timestamp和mysqldump的  (12/16/2012 13:25:41)
  • MySQL保证数据完整性  (12/16/2012 12:00:35)
  • ERROR 1130: mysql 1130连接错误的  (12/16/2012 13:29:08)
  • MySQL数据库教程:管理数据库和表(  (12/16/2012 12:47:02)
  • MySQL快速插入大批量数据存储过程  (11/05/2012 19:04:04)
本文评论 查看全部评论 (0)
表情: 姓名: 字数