6

I want to use many LIKE conditions in my query. I couldn't find a practical solution. I tried CONTAINS but it doesn't work.

Instead of using this

where EIO.DigiAddress like '%abc@abc.com%'
or EIO.DigiAddress like '%def@def.com%'
or EIO.DigiAddress like '%ghi@ghi.com%'

I want to use something like this:

CONTAINS(EIO.DigiAddress,'%abc@abc.com%', '%def@def.com%', '%ghi@ghi.com%')

OR

EIO.DigiAddress IN ('%abc@abc.com%', '%def@def.com%', '%ghi@ghi.com%')
4

3 回答 3

5

尝试这个:

创建临时表:

CREATE TEMPORARY TABLE temp (
    alternate VARCHAR(20)
);

然后:

INSERT INTO temp
VALUES ('%abc@abc.com%'), ('%def@def.com%'), ('%ghi@ghi.com%');

选择:

SELECT t.*
FROM tbl t JOIN temp p ON (t.col LIKE p.alternate);
于 2013-04-19T11:55:49.877 回答
2

我认为使用 LIKE 没有任何问题。但是如果你不喜欢 LIKE 然后使用这个(对于 MS SQLSERVER)

where PATINDEX('%abc@abc.com%', EIO.DigiAddress) >0 OR
      PATINDEX('%def@def.com%', EIO.DigiAddress) >0 OR
      PATINDEX('%ghi@ghi.com%', EIO.DigiAddress) >0

注意:您必须根据您使用的数据库对 PATINDEX 使用相关的字符串函数。

于 2013-04-19T11:49:03.840 回答
1

您可以使用正则表达式执行此操作:

where EIO.DigiAddress regexp '[a-c|e-g|g-i]{3}@{1}[a-c|e-g|g-i]{3}.com'
于 2013-04-19T11:56:55.953 回答