Created
April 3, 2013 16:50
-
-
Save cuheguevara/5303010 to your computer and use it in GitHub Desktop.
split or explode in mysql
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
CREATE FUNCTION explode(isDelimiter VARCHAR(12),inString VARCHAR(255),position INT) | |
RETURNS VARCHAR(255) | |
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(inString, isDelimiter, position), | |
LENGTH(SUBSTRING_INDEX(inString, isDelimiter, position -1)) + 1),isDelimiter, ''); | |
-- usage : | |
-- select explode ('|', 'suhendra|yohana|putra',1); -- give output suhendra | |
-- select explode ('|', 'suhendra|yohana|putra',2); -- give output yohana | |
-- select explode ('|', 'suhendra|yohana|putra',3); -- give output putra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment