oriceon
oriceon

Reputation: 379

MySQL replace all whitespaces with -

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.

Upvotes: 19

Views: 29732

Answers (4)

Jos
Jos

Reputation: 1484

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.

Upvotes: 4

Faiz Mohamed Haneef
Faiz Mohamed Haneef

Reputation: 3596

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

Upvotes: 6

Fokko Driesprong
Fokko Driesprong

Reputation: 2250

This can be achieved with the following MySQL Function:

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

This should replace all the whitespace to a -

Upvotes: 32

tomasBULL
tomasBULL

Reputation: 563

Try this

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

Upvotes: 4

Related Questions