只匹配整个单词与 LIKE? [英] Match only entire words with LIKE?

查看:31
本文介绍了只匹配整个单词与 LIKE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以 'awesome document' LIKE '%doc%' 是真的,因为 doc 是一个子字符串.但是,我希望它是假的,而 'awesome doc' 或 'doc awesome' 或 'awesome doc awesome' 应该是真的.点赞怎么办?

So 'awesome document' LIKE '%doc%' is true, because doc is a sub-string. But, I want it to be false while 'awesome doc' or 'doc awesome' or 'awesome doc awesome' should be true. How can I do with with a like?

我正在使用 sqlite,所以我希望我不必使用一些不可用的东西.

I'm using sqlite, so I hope I don't have to use something that isn't available.

推荐答案

如何分成四部分 -

[MyColumn] Like '% doc %' 
OR [MyColumn] Like '% doc' 
OR [MyColumn] Like 'doc %' 
OR [MyColumn] = 'doc'

另一种方法(仅适用于 ascii 字符)可能是:

An alternate approach (only for ascii chars) could be:

'#'+[MyColumn]+'#' like '%[^a-z0-9]doc[^a-z0-9]%'

(您可能还想处理任何特殊字符)

(You may want to take care of any special char as well)

它看起来不像,但您可能想探索 全文搜索包含,如果这更适合您的情况.

It doesn't look like, but you may want to explore Full Text Search and Contains, in case that's more suitable for your situation.

见:- MSDN:[ ](通配符 - 字符) 匹配) (Transact-SQL)

这篇关于只匹配整个单词与 LIKE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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