0

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!

0

2 Answers 2

4

You can use REPLACE:

REPLACE(str, find_string, replace_with)
Sign up to request clarification or add additional context in comments.

1 Comment

Complete query please! something like UPDATE users REPLACE(phone," ","")
0

Uhmm, solved!, thanks Ferenc Kurucz.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.