MySQL creating a concat_WS delimiter function, one part not working
http://sqlfiddle.com/#!9/ba747/1

You have off-by-one error (in the function and in the expected output too)

555FFFEE1001 should expand to
55:5F:FF:EE:10:01 and not
55:FF:FE:E1:00:01


So all your computations were offset by one character - in the SUBSTRING inside the loop of your function you try to get "last" two characters of a mac, but there you put len as poswhich means you want to start with 12th character - but thats the last one so you cannot get two of them - this means that you loose the first character in the end.

You have to dynamicaly accout for how many characters you want to cut from the end when giving the pos:

CREATE FUNCTION
CONCAT_UNTIL( x LONGTEXT, delim CHAR(1), repeatEvery SMALLINT) RETURNS LONGTEXT
LANGUAGE SQL
NOT DETERMINISTIC
READS SQL DATA
BEGIN
    DECLARE len int unsigned;
    DECLARE erg LONGTEXT;
    SET len = CHARACTER_LENGTH(x);
    REPEAT
        SET erg = CONCAT_WS(delim, SUBSTRING(x, len - repeatEvery + 1, repeatEvery), erg);
        SET len = len - repeatEvery;
   UNTIL len &lt;= 0 END REPEAT;
   return erg;
END//