Skip to content

Instantly share code, notes, and snippets.

@cuheguevara
Created April 3, 2013 16:50
Show Gist options
  • Save cuheguevara/5303007 to your computer and use it in GitHub Desktop.
Save cuheguevara/5303007 to your computer and use it in GitHub Desktop.
split or explode in mysql
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',2); -- give output putra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment