MySQL replace all whitespaces with -

喜你入骨 提交于 2021-02-08 12:18:54

问题


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

Thanks.


回答1:


This can be achieved with the following MySQL Function:

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

This should replace all the whitespace to a -




回答2:


Try this

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



回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/5103116/mysql-replace-all-whitespaces-with

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!