CREATE DEFINER root localhost FUNCTION doLand varchar 26 RETURNS varch

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
CREATE DEFINER=`root`@`localhost` FUNCTION `doLand`(s varchar(26)) RETURNS varchar(26) CHARSET utf8
MODIFIES SQL DATA
begin
declare sub varchar(26);
drop temporary table if exists tmp;
create temporary table tmp (name varchar(26));
while length(s) != 0 do
set sub = substring_index(s, '/', 1);
insert into tmp (name) values (sub);
set s = trim(leading sub from s);
set s = trim(leading '/' from s);
end while;
return (select group_concat(name separator '/') from tmp group by '');
end