MySQL 字符串模式匹配 - like 的替代品

发布于 2024-12-29 00:17:37 字数 579 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑色毁心梦 2025-01-05 00:17:38

另请考虑 SOUNDEX自然语言(使用全文搜索和相关性)搜索。

Also consider SOUNDEX and Natural Language (using full text searches and relevance) searches.

只是我以为 2025-01-05 00:17:37

在这种情况下,你仍然可以使用LIKE

'%$keyword%' LIKE CONCAT('%', Column, '%') 

或者正则表达式:

'%$keyword%' REGEXP Column

In this case, you can still use LIKE:

'%$keyword%' LIKE CONCAT('%', Column, '%') 

Or regular expression:

'%$keyword%' REGEXP Column
女皇必胜 2025-01-05 00:17:37

我不清楚你到底想做什么,但尝试此链接查找有关 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文