tags:

views:

40

answers:

1

Hi,

I'm making one MySql script that break one string field in multiple words.

I need something like the explode function in PHP!

I try the mysql substring_index function but I have to expecify the number of occurences of the one substring. And that is not predictable in one 10.000 row table.

Any sugestion?

this is my actual Stored Procedure:

**CREATE PROCEDURE `extract_words` ()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE result_row CHAR(100);
DECLARE cursor_1 CURSOR FOR SELECT description FROM db_movies;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;


OPEN cursor_1;


REPEAT
  FETCH cursor_1 INTO result_row;
  IF NOT done THEN
    INSERT INTO extrator_words (word) VALUES (result_row);
  END IF;
UNTIL done END REPEAT;


CLOSE cursor_1;

END $$**

Thanks,
Pedro
@pcamacho

+1  A: 
...
SET @currText = textToExpolde;
SET @sepLen   = LENGTH( separator );

WHILE @currText != '' DO

  SET @word     = SUBSTRING_INDEX(@currText, separator, 1);
  SET @currText = SUBSTRING(@currText, LENGTH(@word) + 1 + @sepLen);

  INSERT INTO extractor_words SET word = @word;

END WHILE;
...
Zed
Thanks but! How do you update @currTail?
Pedro
Sorry, that was a typo, that should be currText as well (fixed) =)
Zed
Thank You Very MUCH!It work but you have small error instead of SET @currText = SUBSTRING(@word, LENGTH(@word) + 1 + @sepLen);is: SET @currText = SUBSTRING(@currText, LENGTH(@word) + 1 + @sepLen);
Pedro