创建

DROP PROCEDURE IF EXISTS test;
delimiter $$
CREATE PROCEDURE test(IN uid INT)
BEGIN
select * from table_a where userid=uid;
END; $$
delimiter ;
CALL test(100);

随机字符串

substring(MD5(RAND()),1,5)
-- or
DROP FUNCTION IF EXISTS `random_string`;
delimiter $$
CREATE FUNCTION `random_string`(n int) RETURNS varchar(255) CHARSET utf8
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; $$
SELECT random_string(10);
posted on 2020-01-07 10:12  liehen2046  阅读(114)  评论(0编辑  收藏  举报