如何在 MySQL 中的 instr() 中使用区分大小写?
可能重复: 如何在 instr 中应用通配符MySQL 中的 ()?
可能的重复链接显示了一个与我当前的查询完全相同的查询。但是,我找不到一种方法使其成为敏感匹配。 :\
SELECT COUNT(*) FROM users WHERE INSTR(flags, 'T') > 0;
我得到的计数是 46,这显然是错误的。它计算标志中的每个实例“T”,无论它是大写还是小写。
它按照 MySQL 文档工作。我在 MySQL 文档中发现一些内容,说要在变量上放置“@”符号以使其区分大小写匹配。但是,我在 @'T' 上尝试了此操作以形成以下查询:
SELECT COUNT(*) FROM users WHERE INSTR(flags, @'T') > 0;
我得到的计数为零。
有人能为我解释一下吗? :)
编辑:
忘记提及,抱歉。我还尝试了 LIKE '%T%'
作为 where 子句,但仍然失败并返回与 (INSTR(flags, 'T') > 0)
;
Possible duplicate: How to apply wildcard in instr() in MySQL?
The possible duplicate linked shows a query which is exactly like my current one sort of. However, I cannot find a way to make it a case sensitive match. :\
SELECT COUNT(*) FROM users WHERE INSTR(flags, 'T') > 0;
I get a count of 46 which is obviously wrong. It's counting every instance "T" in flags whether it's upper- or lower-case.
It works as according to the MySQL documentation. I found something in the MySQL docs that said to put an "@" symbol on a variable to make it a case sensitive match. However, I tried this on the @'T' to form the following query:
SELECT COUNT(*) FROM users WHERE INSTR(flags, @'T') > 0;
I get a count of zero.
Could anyone shed some light on this for me? :)
EDIT:
Forgot to mention, sorry. I also tried a LIKE '%T%'
as the where-clause, which still failed and returns the same as (INSTR(flags, 'T') > 0)
;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信这会起作用
I believe this will work
经测试,
按预期生成“0”。根据字符串比较文档,LIKE如果其中一个操作数是二进制的,则执行二进制(因此区分大小写)比较。
Tested,
produces '0', as expected. According to the String Comparison documentation, LIKE performs a binary (thus, case-sensitive) comparison if either of its operands are binary.