使用 LIKE %[keyword]% 搜索关键字 [英] Search keyword with LIKE %[keyword]%

查看:54
本文介绍了使用 LIKE %[keyword]% 搜索关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TransactionDetails 表,其中包含 TransactionIdTransactionDetail 列,这些列用于跟踪应用程序中的所有事务.

I have a TransactionDetails table with TransactionId, TransactionDetail columns, those are used to track all the transactions within the application.

TransactionDetail 的示例记录为:

The sample records of the TransactionDetail are:

[Blah][Log] 20 Records Inserted
[Blah][Exception] Fails on INSERT INTO
[Blah][Error] Authentication Fails Logged
[Blah][Warning] Null value is eliminated by an aggregate
[Blah][Log] 10 Records Deleted 

我想过滤只有 [Log] 的 TransactionDetail 列(Log, Logged 关键字也存在于其他行中).带有 [] 的搜索查询被视为正则表达式模式.我怎样才能跳过它而只获取所需的详细信息.

I want to filter the TransactionDetail columns having the [Log] only (The Log, Logged keyword also exist in the other rows). The search query with [] consider as regular expression pattern. How can I skip that and get the required details only.

我尝试了 [, ] 前面的 \ 转义字符,但它没有返回任何结果.

I have tried the \ escape character in front of the [, ], but it doesn't return any result.

SELECT *
FROM TransactionDetails
WHERE TransactionDetail LIKE '%\[Log\]%'

预期结果:

[Blah][Log] 20 Records Inserted
[Blah][Log] 10 Records Deleted 

SQL 小提琴:http://sqlfiddle.com/#!3/d69f3d/1

推荐答案

通过将 SQL 通配符放入组来转义 SQL 通配符,即:

Escape SQL wildcard characters by putting them in the group, i.e.:

SELECT *
FROM TransactionDetails
WHERE TransactionDetail LIKE '%[[]Log]%'

这篇关于使用 LIKE %[keyword]% 搜索关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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