Created
July 13, 2016 15:23
-
-
Save pierophp/5a1e85767019ff71c8326a7c79bb6c9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delimiter $$ | |
CREATE FUNCTION `SPLIT_STR`( | |
x VARCHAR(255), | |
delim VARCHAR(12), | |
pos INT | |
) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci | |
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | |
CHAR_LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | |
delim, '') | |
$$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
SELECT SPLIT_STR('My String', ' ', 1);