mysql生成随机字符串函数分享
代码如下:
set global log_bin_trust_function_creators = 1; DROP FUNCTION IF EXISTS rand_string; DELIMITER $$ CREATE FUNCTION rand_string(n INT) RETURNS VARCHAR(255) BEGIN DECLARE chars_str varchar(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; DECLARE return_str varchar(255) DEFAULT ''; DECLARE i INT DEFAULT 0; WHILE i < n DO SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*62 ),1)); SET i = i +1; END WHILE; RETURN return_str; END $$ DELIMITER ;
经测试,函数创建后与当前数据库绑定,下面语句可以查看函数相关信息。
代码如下:
SHOW FUNCTION STATUS WHERE Db='database_name';
相关推荐
stulen 2020-08-15
fengzhiwu 2020-08-01
xiaobaif 2020-06-14
lemonzhangyan 2020-06-13
Crazyshark 2020-06-13
weikaixxxxxx 2020-06-13
有梦就能实现 2020-06-10
shengnanonly 2020-06-03
oraclemch 2020-05-30
poplpsure 2020-05-27
zuihaobushi 2020-04-30
luckymaoyy 2020-04-29
唐文 2020-06-06
lijiawnen 2020-05-01
文山羊 2020-10-20
Tristahong 2020-10-14
xiaoseyihe 2020-08-11
amberom 2020-08-03