Mysql中区分大小写使用select where Query [英] Case Sensitive in Mysql using select where Query
本文介绍了Mysql中区分大小写使用select where Query的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Java前端和Mysql后端,
Hi I am using Java front end and Mysql Backend,,,
实际上在 tbl_test 中包含
name value
---------------
abc 22
xyz 14
ABC 32
xyZ 4
ABc 4
在Java中,我尝试检索 abc的值,因此编写了代码
In java I try to retrieve abc's value so written a code
ResultSet result=stmt.executeQuery("select value from tbl_test where name='abc'");
while(result.next())
{
System.out.println("Answer : "+result.getInt(1));
}
result.close();
当前输出为
Answer : 22
Answer : 32
Answer : 4
实际上我只希望结果为"abc",即答案:22
Actually i want the result only 'abc' ie Answer : 22
我也用以下代码找到了结果
I found result also, with below code
String name="abc";
ResultSet result=stmt.executeQuery("select name, value from tbl_test where name='"+name+"'");
while(result.next())
{
if(name.equals(result.getString(1))
System.out.println("Answer : "+result.getInt(2));
}
result.close();
现在我得到正确的输出,但是此结果来自Java代码而不是查询中,是否有可能在查询中检索到相同的结果...
Now i getting correct output, but this result from java code not in query,,, Is it possible to retrieve the same result in query...
谢谢
推荐答案
Use the MySQL Binary
operator:
select value
from tbl_test
where CAST(name AS BINARY) ='abc';
SQL小提琴演示 .
这篇关于Mysql中区分大小写使用select where Query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文