SET @string = '123#456#789';
SET @delimiter = '#';
SET @index = 1;
WHILE @index <= 3 DO
SELECT REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@string, @delimiter, @index)), @delimiter, 1));
SET @index = @index + 1;
END WHILE;
SET @delimiter = '#';
SET @index = 1;
WHILE @index <= 3 DO
SELECT REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@string, @delimiter, @index)), @delimiter, 1));
SET @index = @index + 1;
END WHILE;