mysql字段分割再做拼接
create function func_getSplitCount(f_string varchar(1000),f_delimit varchar(5)) returns int(11)
BEGIN
return 1+(length(f_string) - length(replace (f_string,f_delimit,'')));
END
得到分割字段的长度 create function func_getSplitString(f_string varchar(1000),f_delimit varchar(5),f_order int) returns varchar(255)
BEGIN
declare result varchar(255) default '';
select name into result from t_latitude where id=(reverse(substring_index(reverse(substring_index(f_string,f_delimit,f_order)),f_delimit,1)));
return result;
END
获取分割字段对应的一条记录namecreate function func_getStrTotal(f_string varchar(1000)) returns varchar(255)
BEGIN
declare loopCount int default 1;
declare temp_orWhere varchar(255) default '';
set loopCount = func_getSplitCount(f_string,',');
WHILE(loopCount > 0) DO
set temp_orWhere = concat(temp_orWhere,',',func_getSplitString(f_string,',',loopCount));
set loopCount = loopCount - 1;
END WHILE;
return substring(temp_orWhere,2);
END
将name字段重新拼接起来