如何在mysql字符串中将多个空格替换为单个空格。
答案 0 :(得分:2)
DELIMITER $$
CREATE PROCEDURE I_hate_duplicate_spaces
BEGIN
DECLARE rows_affected INTEGER;
REPEAT
UPDATE table1 SET afield = REPLACE(afield,' ',' ');
SELECT ROW_COUNT() INTO rows_affected;
UNTIL rows_affected = 0 END REPEAT;
END $$
DELIMITER ;
现在启动存储过程:
CALL I_hate_duplicate_spaces;
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html
答案 1 :(得分:1)
基本上你想在MySQL中做一个像PHP的preg_replace('/ +/', ' ', $sString)
那样的正则表达式替换 - 遗憾的是,这不是MySQL内置的,所以你需要一个用户定义的函数......这导致我: How to do a regular expression replace in MySQL?
希望有帮助...