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

MYSQL
MySQL代码如何在 Windows环境下编译
MYSQL出错代码列表
mysql 5.0存储过程学习总结
迅速帮你解决 SQL Server 日志满问题
SQL Server 2005 中能够使用 Try...Catch语句
启动SQL SERVER时自动执行存储过程
无法在SQL 2005系统数据库中执行的T-SQL语句(XML处理)
MySQL关系数据库系统IF查询处理远程拒绝服务漏洞
SQL Server 用户自定义的数据库修复
运行SQL Server的计算机之间移动数据库
jsp从数据库取得数据作为下拉菜单选项的实现
sql server2005 jdbc解决自动增长列统一处理问题纪实
使你的 SQL 语句完全优化
动态网页编程中优化数据库注意的十大原则
SQL Server 2000数据库中如何重建索引
mysql全文搜索索引的字段提高搜索效率
轻松八句话 教会你完全搞定MySQL数据库
MySQL数据库中数据库移植中的乱码问题
分析数据库备份过程中九种可能出现的情况
对付ARP欺骗攻击16a.us病毒的解决方案

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


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