我正在制作一个 MySql 脚本,它将一个字符串字段分解为多个单词。
我需要类似 PHP 中的爆炸函数之类的东西!
我尝试了 mysql substring_index 函数,但我必须指定一个子字符串出现的次数。这在一个 10,000 行的表中是不可预测的。
有什么建议吗?
这是我实际的存储过程:
**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 $$**
谢谢,
佩德罗
@pcamacho
最佳答案
...
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;
...
关于sql - MySql 字段子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1306915/