MySQL 隨機(jī)密碼生成代碼
更新時(shí)間:2009年09月12日 22:15:00 作者:
晚上有朋友問起,簡單的寫了一個(gè)。
復(fù)制代碼 代碼如下:
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 ;
調(diào)用方法示例:
復(fù)制代碼 代碼如下:
select func_rand_string(12,3);
相關(guān)文章
詳解MySQL安裝及MySQL8.0新密碼認(rèn)證方式
這篇文章主要介紹了詳解MySQL安裝及MySQL8.0新密碼認(rèn)證方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09mysql-5.5.28源碼安裝過程中錯(cuò)誤總結(jié)
介紹一下關(guān)于mysql-5.5.28源碼安裝過程中幾大錯(cuò)誤總結(jié),希望此文章對(duì)各位同學(xué)有所幫助。2013-10-10