标签:floor 字符串 efault sql and $$ 函数 mys 生成随机字符串
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 ;
标签:floor 字符串 efault sql and $$ 函数 mys 生成随机字符串
原文地址:http://www.cnblogs.com/chenminklutz/p/7857431.html