SQL - 查询存储不一致的电话号码 [英] SQL - Query Phonenumber that are stored inconsistently

查看:23
本文介绍了SQL - 查询存储不一致的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的数据库中有一个电话号码字段,我想做一个简单的查找查询,例如:

we a phonenumber field in our database and I would like to do a simple lookup query like:

SELECT * FROM TABLE WHERE Phonenumber = '555123456'

但是由于电话号码是由用户输入的并且没有经过标准化处理,所以我们真的不知道它们的样子.

But since the phonenumbers are entered by users and are not normalized, we don't really know what they look like.

可能是:

  • +555-123456

  • (555) 123 456

  • 555-12-34-56

或者完全不同的东西.

唯一可以确定的是,所有给定的数字都应该以正确的顺序出现.是否可以围绕它构建查询?

The only thing certain is that the all the given numbers should be there in the correct order. Is it possible to construct a query around that?

推荐答案

由于不知道你要找什么 RDBMS,我就给个最通用的方法:

Since I don't know what RDBMS you're looking for, I'll give the most generic way:

phonenumber like '%5%5%5%1%2%3%4%5%6%'

这假设所有电话号码的长度至少相等(以数字为单位).

This assumes that all phone numbers are at least equal length (in digits).

这篇关于SQL - 查询存储不一致的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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