The following function definition creates a split() function that splits a string by a given delimiter and returns the specified element.
DROP FUNCTION IF EXISTS split;
CREATE FUNCTION split (str TEXT, delim VARCHAR(1), N INT)
RETURNS TEXT DETERMINISTIC
RETURN SUBSTRING(SUBSTRING_INDEX(str, delim, N), LENGTH(SUBSTRING_INDEX(str, delim, N - 1)) + LENGTH(delim) + (N > 1))
The syntax of the function is as follows.
split(str, separator, pos)
Set as favorite
Bookmark
Email This
Hits: 148
Comments (0)

Write comment
You must be logged in to post a comment. Please register if you do not have an account yet.