1

I have the need to identify records in my database that contain a phone number so that I can send them on to a contact team.

Example: tblData

  • id
  • comment
  • dtCreate

Given this table structure, the query might be:

SELECT * FROM tblData WHERE comment [HeresWhereINeedHelp]

The comment might (and likely will) contain all sorts of other data. An example comment:

Yea, I had a terrible experience. I'd like for someone to call me at 111.222.3333. Thank you.

The record containing this comment should be pulled in the query because it contains a phone number.

I tried an extended SPROC that enabled regex searching, but the performance was terrible. The system is SQL Server 2012.

Many thanks for any direction.

4

2 に答える 2

4

LIKE演算子を確認する必要があります。あなたの場合、あなたはおそらく

WHERE comment LIKE '%[0-9][0-9][0-9]_[0-9][0-9][0-9]_[0-9][0-9][0-9][0-9]%'

文字列内の任意の場所を検索しているため、大きなデータセットを処理するのにも長い時間がかかります-入力時にコメントフィールドで電話番号を確認し、その行にフラグを付けてフラグを立てることもできます。そのように、その列ContainsPhoneNumber (bit).にインデックスを付けて、より高速なルックアップを行うことができます。

于 2012-11-14T20:32:00.337 に答える
0

10桁の整数として保存されている電話番号用に別のテーブルを作成します。
正規表現を1回実行して、電話番号を解析します。
その列にインデックスを付けると、インデックスシーク速度が得られます。

于 2012-11-14T20:48:23.247 に答える