手机
当前位置:查字典教程网 >编程开发 >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创建数据库和数据库表代码

MySQL取出随机数据

MySQL数据库管理常用命令小结

MYSQL 修改root密码命令小结

MySQL数据库的出错代码列表

MySQL数据库备份与恢复方法

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

MySQL 有输入输出参数的存储过程实例

MySQL 密码设置

MYSQL导入导出命令详解

精品推荐
分类导航