Erich García
Erich García

Reputation: 1874

MySQL TRIM spaces inside text

I have a DB with users table. One of the fields is cellphone, but is as VARCHAR type. Some users modify their phone with correct and desired behavior, a number without spaces. But other users just add it and let spaces between chars.

Desired data:
5354663598

Some cases:
53 5 466 3598

In PHP I can solve this with a foreach, and later a str_replace(" ", "", $user->cellphone);

But I just want to know if there is a MySQL function for it.

Thanks!

Upvotes: 0

Views: 62

Answers (2)

Erich García
Erich García

Reputation: 1874

Uhmm, solved!, thanks Ferenc Kurucz.

UPDATE users SET phone = REPLACE(phone," ","")

Upvotes: 0

Ferenc Kurucz
Ferenc Kurucz

Reputation: 142

You can use REPLACE:

REPLACE(str, find_string, replace_with)

Upvotes: 4

Related Questions