更新时间:2023-01-30 11:34:47
使用sql LIKE
时:
您应该使用通配符标识符,例如(或不使用):
You should use a wildcard identifier such as (or not):
'%word'
-返回值以字母"word"结尾的结果.'word%'
-翻阅以字母"word"开头的结果.%word%
-返回结果,该结果在任何地方都包含字母:"word".还有更多模式搜索组合,例如:
'%word'
- return results that the value ends with the letters: "word".'word%'
- reurn results that begin with the letters: "word".%word%
- return results that include the letters: "word" anywhere.there are some more pattern search combination like:
'abc'喜欢'abc'true
'abc' LIKE 'abc' true
'abc'喜欢'a%'是
'abc' LIKE 'a%' true
'abc'喜欢' b '是
'abc'喜欢'c'false
'abc' LIKE 'c' false
如果您想要完全匹配,则应使用:
If you want an exact match you should use:
"SELECT * FROM hobby WHERE name='Beading'"
但是LIKE 'Beading'
也应该起作用,因此可能是空格问题或区分大小写的问题.
But LIKE 'Beading'
should work also, so its probably a spaces issue or case sensitivity porblem.
当您要确保结果完整时,需要注意排序规则的大小写(敏感性).
You need to take care of collation case (sensitivity) when you want to make sure your results are complete.
假设您的表是UTF ... CS,并且要进行不区分大小写的搜索,则应在sql查询中声明它,例如:
Say your table is UTF...CS and you want to make an insensitive case search you should declare it in your sql query, for example:
SELECT * FROM hobby WHERE name COLLATE UTF8_GENERAL_CI LIKE 'beading'
尝试测试不同的方法,看看最适合您的目标.
try testing different approaches and see what fits your goal best.