清除mySql中的电话号码字段 [英] Cleaning out a field of Phone numbers in mySql

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

问题描述

不是数据库专家,而是:我在继承的mySql数据库中混合了数据.

In not a database guy but: I have mixed up data in a mySql database that I inherited.

某些电话号码的格式为(512) 555-1212(称为脏电话) 其他5125551212(干净)

Some Phone numbers are formatted (512) 555-1212 (call it dirty) Others 5125551212 (Call it clean)

我需要一个显示

UPDATE table_name
SET Phone="clean'(Some sort of cleaning code  -  regex?)
WHERE Phone='Dirty'

推荐答案

不幸的是,MySQL中没有正则表达式替换/更新.如果只是括号,破折号和空格,那么一些嵌套的REPLACE调用就可以解决问题:

Unfortunately there's no regex replace/update in MySQL. If it's just parentheses and dashes and spaces then some nested REPLACE calls will do the trick:

UPDATE table_name
SET Phone = REPLACE(REPLACE(REPLACE(REPLACE(Phone, '-', ''), ')', ''), '(', ''), ' ', '')

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

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