Is there something analogous to a split() method in mySql?

前端 未结 3 424
粉色の甜心
粉色の甜心 2021-01-20 23:54

I\'m looking to write a stored procedure that takes as a parameter a string that\'s delimited by a token and then to run a while loop in the procedure for every item in that str

3条回答
  •  遇见更好的自我
    2021-01-21 00:43

    I think you'll need to roll your own function. substring_index will come in handy:

    SUBSTRING_INDEX(str,delim,count)

    Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.

    mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
            -> 'www.mysql'
    mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
            -> 'mysql.com'
    

    This function is multi-byte safe.

提交回复
热议问题