在MySQL中格式化电话号码 [英] Format Phone Numbers in MySQL

查看:142
本文介绍了在MySQL中格式化电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有一堆电话号码,格式如下:(999)123-3456.

I have a bunch of phone numbers in a DB that are formatted as such: (999) 123-3456.

我需要他们看起来像123-123-1234

I'm needing them to look like 123-123-1234

是否存在某种正则表达式或我可以在MySQL中执行的操作以快速格式化所有这些电话号码? 另外,令人沮丧的是,有些格式不是这样,所以我不能只将其应用于整个列.

Is there any sort of regex or something I can do in MySQL to quickly format all these phone numbers? Also, frustratingly, some are NOT formatted like that, so I couldn't just apply this to an entire column.

谢谢!

推荐答案

一种快速的解决方案是运行以​​下两个查询:

A quick solution would be to run these two queries:

UPDATE table_name set PhoneCol = REPLACE(PhoneCol, '(', '');
UPDATE table_name set PhoneCol = REPLACE(PhoneCol, ') ', '-');

这篇关于在MySQL中格式化电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆