Created
August 17, 2016 18:34
-
-
Save jesgs/6788c60aef50b61b5f85aae0370f2999 to your computer and use it in GitHub Desktop.
Found: http://stackoverflow.com/questions/5928599/equivalent-of-explode-to-work-with-strings-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
DELIMITER | | |
CREATE PROCEDURE explode( pDelim VARCHAR(32), pStr TEXT) | |
BEGIN | |
DROP TABLE IF EXISTS temp_explode; | |
CREATE TEMPORARY TABLE temp_explode (id INT AUTO_INCREMENT PRIMARY KEY NOT NULL, word VARCHAR(40)); | |
SET @sql := CONCAT('INSERT INTO temp_explode (word) VALUES (', REPLACE(QUOTE(pStr), pDelim, '\'), (\''), ')'); | |
PREPARE myStmt FROM @sql; | |
EXECUTE myStmt; | |
END | | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment