手机
当前位置:查字典教程网 >编程开发 >mysql数据库 >MySQL 随机密码生成代码
MySQL 随机密码生成代码
摘要:复制代码代码如下:DELIMITER$$CREATEFUNCTION`t_girl`.`func_rand_string`(f_numtin...

复制代码 代码如下:

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);

【MySQL 随机密码生成代码】相关文章:

MySQL获取所有分类的前N条记录

用MySQL创建数据库和数据库表代码

MySQL数据库备份与恢复方法

MySQL定期自动删除表

SQL查询时生成的临时文件对数据库查询的影响

MySQL 密码设置

MYSQL数据库出错代码列表

MySQL数据库十大优化技巧

MySQL5创建存储过程的示例

MySQL ORDER BY 的实现分析

精品推荐
分类导航