使用 LIKE %[keyword]% 搜索关键字 [英] Search keyword with LIKE %[keyword]%
问题描述
我有一个 TransactionDetails
表,其中包含 TransactionId
、TransactionDetail
列,这些列用于跟踪应用程序中的所有事务.
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屋!