MySQL 随机密码生成代码
更新时间:2009年09月12日 22:15:00 作者:
晚上有朋友问起,简单的写了一个。
复制代码 代码如下:
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);
相关文章
MySQL错误“Specified key was too long; max key length is 1000 b
今天在为数据库中的某两个字段设置unique索引的时候,出现了Specified key was too long; max key length is 1000 bytes错误2010-08-08
CentOS7.x卸载与安装MySQL5.7的操作过程及编码格式的修改方法
这篇文章主要介绍了CentOS7.x卸载与安装MySQL5.7的操作过程及编码格式的修改方法,本文图文并茂给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下2019-05-05


最新评论