MYSQL Split/Explode function
Do you know any MYSQL split function or Explode function ? I guess no, as MYSQL does not have any function for split string or explode string. Today i need to explode one of my database field which contains latitude and longitude and need to check latitude and longitude in WHERE condition for getting records by some distance. You can do this by creating one fuction in database and than call it from MYSQL Query.
– Create function for database
CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, '');
– How to use above created function
SELECT SPLIT_STR(string, separator, position) SELECT SPLIT_STR('12.25,21.75', ',', 1) as first;
Let me know if you find any problem.