MySQL 将所有空格替换为 -

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5103116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:53:44  来源:igfitidea点击:

MySQL replace all whitespaces with -

mysqlsql

提问by oriceon

how could i remove ALL whitespaces from a row? I see here alot of same question but all answers ar to use replace option. Replace will work only to strip one spaces, not all.

我怎么能从一行中删除所有空格?我在这里看到很多相同的问题,但所有答案都使用替换选项。替换只能去除一个空格,而不是全部。

ex: a b c to become a-b-c

例如:abc 变成 abc

Thanks.

谢谢。

回答by Fokko Driesprong

This can be achieved with the following MySQL Function:

这可以通过以下 MySQL 函数来实现:

SELECT REPLACE( table.field, ' ', '-' ) FROM table;

This should replace all the whitespace to a -

这应该将所有空格替换为 -

回答by tomasBULL

Try this

尝试这个

replace('a b c',' ','-')

回答by Faiz Mohamed Haneef

update image set path =  REPLACE( image.path, ' ', '-' ) where path like '% %'

if you would like to update the path in mysql itself use the update for all rows which have spaces withe %20

如果您想更新 mysql 本身中的路径,请对所有带有 %20 空格的行进行更新

回答by JosFabre

UPDATE table SET table.field = REPLACE( table.field, ' ', '-' );

This will update all the fields, replacing all spaces with hyphens. This will actually modify the data in the tables. Fokko's answer above will change only the data that is pulled, therefore not changing the actual data.

这将更新所有字段,用连字符替换所有空格。这实际上将修改表中的数据。上面 Fokko 的回答只会更改拉取的数据,因此不会更改实际数据。