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

MYSQL
MYSQL初学者扫盲
PHP+MYSQL网站开发基础知识
网站主机教程(7):网站主机的数据库技术
PHP基础教程(2):PHP安装
PHP+MySQL教程(1):MYSQL简介
PHP+MySQL教程(2):连接MYSQL数据库
PHP+MySQL教程(3):创建数据库和表
PHP+MySQL教程(4):MySQL Insert Into
PHP+MySQL教程(5):MySQL Select
PHP+MySQL教程(6):MySQL Where子句
PHP+MySQL教程(7):MySQL Order By关键词
PHP+MySQL教程(8):MySQL Update
PHP+MySQL教程(9):MySQL Delete From
PHP+MySQL教程(10):Database ODBC
PHP+AJAX教程(5):AJAX MySQL数据库实例
32位的MySQL数据库迁移到64位的MySQL数据库
MYSQL教程:MYSQL数据值类型(data type)
MYSQL教程:MYSQL列类型(column type)
MYSQL数据库教程:唯一编号
MYSQL教程:MYSQL字符集支持

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


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