IF l_type = 1 THEN
SET v_chars = '0123456789';
ELSEIF l_type = 2 THEN
SET v_chars = 'abcdefghijklmnopqrstuvwxyz';
ELSEIF l_type = 3 THEN
SET v_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
ELSEIF l_type = 4 THEN
SET v_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
ELSEIF l_type = 5 THEN
SET v_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
ELSE
SET v_chars = '0123456789';
END IF;
WHILE i < l_num DO
SET result = concat( result,substr(v_chars,ceil(rand()*(length(v_chars)-1)),1) );
SET i = i + 1;
END WHILE;
RETURN result;
END;
//
delimiter ;