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

MYSQL
Timeout error occurred trying to start MySQL Daemon
Phpcms2008网站内容管理系统免费开源
PHP教程:常用mysql操作
MySQL教程:Order By用法
MYSQL导入数据Got a packet bigger than...错误
MySQL安装向导所作的更改
MySQL教程:Order By索引优化
MySQL教程:Order By语法
MySQL教程:Order By Rand()
MySQL教程:Replace INTO说明
MySQL server has gone away问题原因
MySQL教程:Group By用法
MySQL命令终端有beep声
mysql与sqlserver的所有区别
SQLite数据库最适合做网站内容管理系统(CMS)
mysql proxy问题
Windows下PHP+MySQL+IIS安全平台搭建
e2php搭建Windows下Apache+PHP+MySQL环境
PHP简单学习,保证入门学会
MYSQL的DATE_FORMAT()格式化日期

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 97 ::
收藏到网摘: 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);