分割出多少个字符串split_count(str,delimiter)
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `split_count`(
f_string varchar(1000),f_delimiter varchar(100)
) RETURNS int(11)
BEGIN
return 1+(length(f_string) - length(replace(f_string,f_delimiter,''))) / length(f_delimiter);
END$$
DELIMITER ;
获取分割出的第n个字符串split(str,delimiter,n),n从1开始,当n大于split_count时返回空字符串
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `split`(
f_string varchar(1000),f_delimiter varchar(100),f_order int) RETURNS varchar(1000) CHARSET utf8
BEGIN
declare result varchar(1000) default '';
set result = reverse(substring_index(reverse(substring_index(f_string,f_delimiter,f_order)),reverse(f_delimiter),1));
return result;
END$$
DELIMITER ;