开发者

MySQL - convert phone number data?

开发者 https://www.devze.com 2023-01-06 14:26 出处:网络
I have a MySQL Inno开发者_Python百科DB database. I have a \'phone_number\' field. My data is dirtly in the sense that sometimes my data is:

I have a MySQL Inno开发者_Python百科DB database.

I have a 'phone_number' field.

My data is dirtly in the sense that sometimes my data is:

(111) 222-3333
111-222-3333
111.222.3333
(111) 222 3333

How can I strip all spaces and parenthesis from my 'phone_number' field to only store my phone_number in the following format '1112223333'?

What would the SQL be to UPDATE my 'phone_number' field to have all data in the format '1112223333'?

For example, pseudo code:

UPDATE phone_number = STRIP_SPACES_AND_PARATENSIS(phone_number) FROM homes;


Use this sql query:

update homes set phone_number=replace(replace(replace(replace(replace(phone_number,'-',''),'(',''),')',''),'.', ''), ' ', '');
0

精彩评论

暂无评论...
验证码 换一张
取 消