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

MYSQL
图片通过asp.net上传到mysql数据库的方法
mysql教程之存储
用来分析、监控和变换通信数据MySQL-Proxy
MySQL教程:相关的环境变量
MySQL新功能测试
MySQL数据库规范化设计
MySQL故障检测和修正的一般过程
写给菜鸟站长:解读你的茫然
如何取得MYSQL中ENUM列的全部可能值
mysql基础教程:安装与操作
phpMyAdmin安装方法及介绍
MySQL:改善数据装载效率的策略分析
为MySQL数据库换挡加速
MySQL参数是如何设置的
mysql中如何随机提取数据库记录
Windows下MySQL安全权限设置
WordPress基础,让你全面了解WordPress
Photoshop教程:绘制著名博客程序的LOGO
PHP通过SQL语句将数据写入MySQL数据库指定的表
Six6免费空间,6G容量,无限月流量

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


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