MySQL 字符串模式匹配 - like 的替代品
MySQL like 子句允许通配符搜索,例如'%keyword%'
,其中关键字夹在列值中。
对于关键字包含列值的一部分并且 %keyword%
不起作用的模式匹配,我们可以使用 INSTR
函数进行搜索。
示例:
Column="Apple"
$keyword = "An Apple a day"
在这里,我们不能使用 Column like '%$keyword%'
来进行匹配,但 (INSTR('$Keyword', Column)>0
会执行 除了 INSTR 之外,我们还有哪些替代方案(正则表达式?、全文搜索?、lucene? )
来进行模式匹配(示例?)
更新:
Column = "Golden Apple"
$keyword = "An Apple a day"
即使对于这样的示例,我也想能够匹配$关键字与列,因为它们有一个共同术语“Apple”。
MySQL like clause lets wildcard searches like '%keyword%'
where keyword is sandwiched within the column value.
For pattern matching where the keyword contains a part of the column value and when %keyword%
will not work, we can use INSTR
function to do the search.
Example:
Column="Apple"
$keyword = "An Apple a day"
Here, we cannot do Column like '%$keyword%'
to make a match but (INSTR('$Keyword', Column)>0
would do the match.
What alternatives (regex?, fulltext search?, lucene?) do we have other than INSTR for pattern-matching such cases (examples?) ?
Update:
Column = "Golden Apple"
$keyword = "An Apple a day"
Even for samples like this, I would like to be able to match the $keyword with column as they have a common term "Apple".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另请考虑 SOUNDEX 和 自然语言(使用全文搜索和相关性)搜索。
Also consider SOUNDEX and Natural Language (using full text searches and relevance) searches.
在这种情况下,你仍然可以使用
LIKE
:或者正则表达式:
In this case, you can still use
LIKE
:Or regular expression:
我不清楚你到底想做什么,但尝试此链接查找有关 mysql 中的模式匹配
您在编写过程、触发器还是只是一个选择?
I don't understand clearly what exactly you want to do, but try this link to find the help about pattern matching in mysql
Are you writing a procedure,a trigger, or simply a select?