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

MYSQL
mysql "too many connections" 错误 之 mysql解决方法
MySQL: mysql is not running but lock exists 的解决方法
使用mysql中遇到的几个问题
MySQL一个索引最多有多少个列?真实的测试例子
MySQL里Create Index 能否创建主键 Primary Key
MySQL 创建索引(Create Index)的方法和语法结构及例子
MYSQL 优化常用方法
linux mysql 找回密码
mysql 动态执行存储过程语句
MySQL 查找价格最高的图书经销商的几种SQL语句
MySQL 客户端不输入用户名和密码直接连接数据库的2个方法
mysql 查询表中平均分最低的班级
mysql 左连接、右连接和内连接
Mysql LONGBLOB 类型存储二进制数据 (修改+调试+整理)
Mysql LONGTEXT 类型存储大文件(二进制也可以) (修改+调试+整理)
Mysql 插入中文及中文查询 (修改+调试)
mysql 数据表中查找重复记录
MySql .frm数据库文件导入的问题
解决hibernate+mysql写入数据库乱码
mySQL UNION运算符的默认规则研究

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


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