Mysql 如何替换表列中的所有特殊字符和空格?
我有一个名为“联系人”的表,其中包含以下字段Mysql 如何替换表列中的所有特殊字符和空格?,mysql,Mysql,我有一个名为“联系人”的表,其中包含以下字段 id | phone_mobile 1 | 9988011223 2 | 00-12-123456 3 | 91-8876980987 4 | (91) 88990099777 我想要一个select查询,它将返回下面的输出 id | phone_mobile 1 | 9988011223 2 | 0012123456 3 | 918876980987 4 | 9188990099777 对于已知的字符集,您可以使用repla
id | phone_mobile
1 | 9988011223
2 | 00-12-123456
3 | 91-8876980987
4 | (91) 88990099777
我想要一个select查询,它将返回下面的输出
id | phone_mobile
1 | 9988011223
2 | 0012123456
3 | 918876980987
4 | 9188990099777
对于已知的字符集,您可以使用
replace()
mysql> select replace(replace(replace('00-12-123456','-',''),'(',''),')','');
+----------------------------------------------------------------+
| replace(replace(replace('00-12-123456','-',''),'(',''),')','') |
+----------------------------------------------------------------+
| 0012123456 |
+----------------------------------------------------------------+
所以在你的情况下可能是
select
id,
replace(replace(replace(replace(phone_mobile,'-',''),'(',''),')',''),' ','') as phone_mobile
from table_name
如果要替换的字符列表很长,那么最好使用应用程序级别来完成这项工作,因为替换的链接会变得非常混乱。对于已知的字符集,可以使用replace()
函数链接如下内容:
mysql> select replace(replace(replace('00-12-123456','-',''),'(',''),')','');
+----------------------------------------------------------------+
| replace(replace(replace('00-12-123456','-',''),'(',''),')','') |
+----------------------------------------------------------------+
| 0012123456 |
+----------------------------------------------------------------+
所以在你的情况下可能是
select
id,
replace(replace(replace(replace(phone_mobile,'-',''),'(',''),')',''),' ','') as phone_mobile
from table_name
如果要替换的字符列表很长,那么最好使用应用程序级别来完成这项工作,因为替换的链接会变得非常混乱。对于已知的字符集,可以使用replace()
函数链接如下内容:
mysql> select replace(replace(replace('00-12-123456','-',''),'(',''),')','');
+----------------------------------------------------------------+
| replace(replace(replace('00-12-123456','-',''),'(',''),')','') |
+----------------------------------------------------------------+
| 0012123456 |
+----------------------------------------------------------------+
所以在你的情况下可能是
select
id,
replace(replace(replace(replace(phone_mobile,'-',''),'(',''),')',''),' ','') as phone_mobile
from table_name
如果要替换的字符列表很长,那么最好使用应用程序级别来完成这项工作,因为替换的链接会变得非常混乱。对于已知的字符集,可以使用replace()
函数链接如下内容:
mysql> select replace(replace(replace('00-12-123456','-',''),'(',''),')','');
+----------------------------------------------------------------+
| replace(replace(replace('00-12-123456','-',''),'(',''),')','') |
+----------------------------------------------------------------+
| 0012123456 |
+----------------------------------------------------------------+
所以在你的情况下可能是
select
id,
replace(replace(replace(replace(phone_mobile,'-',''),'(',''),')',''),' ','') as phone_mobile
from table_name
如果要替换的字符列表很长,那么最好使用应用程序级别来完成这项工作,因为replace的链接变得非常混乱