复制代码 代码如下:
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);
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 slave不能同步Last_SQL_Error Error Duplicate entry
- MySQL 提示Incorrect key file for table 'xx'; try to 出错无法打开
- MySQL Got error 28 from storage engine 解决办法
- 高可用的Mysql双机热备(Mysql_HA)
- mysql 对数据表的结构和数据进行复制
- mysql数据库表的错误 got error 28 from storage engine
- MySQL存储过程中使用动态行转列
- 查看运行MySQL中的语句(查询正在执行的sql)
- mysql安装图解 mysql图文安装教程(详细说明)
- Can't connect to MySQL server on localhost (10061)解决方法