当前位置: 首页 > 图文教程 > 数据库 > MYSQL > MySQL 随机密码生成代码

MYSQL
V3host.be 比利时150M可绑米DA面板免费PHP空间
教程:MYSQL创建触发程序的方法
教程:MySQL中多表操作和批处理方法
关于MySQL中隐藏空间的问题
MySQL数据库在Linux下二进制日志恢复方法
分析与比较五种MySQL数据库可靠性方案
在Ubuntu下的MySQL数据库如何更改存储位置
MySQL插入表格查询的技巧
介绍MySQL用户root密码为空的另类攻击方法
MySQL数据库的23个安全注意事项
浅谈MySQL+PHP产生乱码的原理及解决方法
浅析MySQL中隐藏空间问题
使用Netbeans操作MySQL数据库的方法
lighttpd+PHP(FAST-CGI)++MySQL的具体步骤
浅谈MySQL数据库中如何解决分组统计的问题
MySQL与.NET应用解析
MySQL数据库中的安全解决方案
MyISAM-性能与特性的折中
MySQL数据库环境使用攻略
MYSQL没有完全卸载将导致其安装不成功

MYSQL 中的 MySQL 随机密码生成代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 105 ::
收藏到网摘: n/a

晚上有朋友问起,简单的写了一个。
复制代码 代码如下:

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);