I found a lot of examples of split-procedures for MySql returning the xth-part of a string. But I need a split-procedure to return ALL parts of a splitted string, so someling like:
SELECT split(",", "1,2,3,4,5,6");
Should return;
+-------+
| split |
+-------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+-------+
I tried:
DELIMITER $$
CREATE PROCEDURE `split`(delimeter VARCHAR(1),txt VARCHAR(65535))
RETURNS split TABLE (
part varchar(1024) NOT NULL)
DETERMINISTIC
BEGIN
DECLARE pos, posOld;
set pos := locate(delimeter,txt);
set posOld = 1;
WHILE pos > 0 DO
set part := subst(text, posOld, pos-1);
set posOld := pos+1;
insert into split (`part`) values (part);
set pos := locate(delimeter, txt, posOld);
END WHILE;
END$$
but get the error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'split TABLE (part varchar(1024) NOT NULL)
Whats the correct way to do it?