Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql TRIM not working

Tags:

php

mysql

I'm trying to cleanse my numbers in my database by using :

update valuations set Telephone = TRIM(Telephone) where  1 = 1

but 0 rows are effected and all the nunmbers still have a space in them. The datatype is varchar so im unsure why this isn't working - can anyone help?

Thanks

like image 230
Gaz Smith Avatar asked Dec 18 '22 14:12

Gaz Smith


2 Answers

As I said in my comment, I'm guessing your spaces are in the middle of your entries, TRIM won't work then. Use REPLACE instead :

UPDATE valuations SET Telephone = REPLACE(Telephone, ' ', '') WHERE 1 = 1;
like image 149
roberto06 Avatar answered Jan 07 '23 11:01

roberto06


trim() will remove only those spaces at the ends of a string. If you want to remove those inside the string, use replace:

UPDATE valuations SET Telephone = REPLACE(Telephone, ' ', '') where  1 = 1
like image 24
Mike B Avatar answered Jan 07 '23 11:01

Mike B