Split a string

from the Artful Common Queries page


CREATE FUNCTION SPLIT_STR( s VARCHAR(255), delim VARCHAR(16),  pos INT )
RETURNS VARCHAR(255)
RETURN REPLACE( SUBSTRING( SUBSTRING_INDEX(s, delim, pos),
                           LENGTH(SUBSTRING_INDEX(s, delim, pos -1)) + 1),
                delim, 
                ''
              );
For longer strings, change the datatype.

Last updated 27 Jan 2012




Return to the Artful Common Queries page