Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL replace all whitespaces with -

Tags:

sql

mysql

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.

like image 983
oriceon Avatar asked Feb 24 '11 10:02

oriceon


People also ask

How do I remove all spaces from a string in MySQL?

Remove all the whitespaces from the entire column values We will be using the replace() function as replace() function will remove the white spaces from between, start, and the end of the string value. Name of the table. Name of the column whose values are to be updated.

Which function is used in MySQL to remove all the whitespace from a particular string?

The TRIM() function returns a string that has unwanted characters removed. Note that to remove the leading spaces from a string, you use the LTRIM() function. And to remove trailing spaces from a string, you use the RTRIM() function.

How do I change double spacing to single space in MySQL?

The function REPLACE(str, " ", " ") only removes double spaces, but leaves multiples spaces when there are more... Check this answer stackoverflow.com/questions/986826/… . The OP wants to do the same but with other characters.


1 Answers

This can be achieved with the following MySQL Function:

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

This should replace all the whitespace to a -

like image 129
Fokko Driesprong Avatar answered Sep 23 '22 13:09

Fokko Driesprong