简体   繁体   English

如何以不区分大小写的方式在MySQL中搜索

[英]How to search in MySQL in a case-insensitive way

How can I search for a user even if I don't know the exact spelling with regards to case, like 即使我不知道大小写的确切拼写,该如何搜索用户,例如

SELECT * FROM USER WHERE U.NAME =  'STEVEN';

Meaning: if a user has the name "Steven" or "sTEVEN" how can I search all persons who have this name? 含义:如果用户的名称为“ Steven”或“ sTEVEN”,我该如何搜索所有使用此名称的人?

I tried it, but it does not work. 我试过了,但是没有用。

WHERE email LIKE '%GMAIL%'

It did not not work when case was lowercase. 小写时不起作用。

The case sensitivity is based on the character set and collation of the table. 区分大小写基于表的字符集和排序规则。

The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. 默认字符集和排序规则为latin1和latin1_swedish_ci,因此默认情况下非二进制字符串比较不区分大小写。

http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html http://dev.mysql.com/doc/refman/5.0/en/case-sensitiveivity.html

You may want to look at the collation of your table if the searches are case-sensitive. 如果搜索区分大小写,则可能需要查看表的排序规则。

使用UPPER

SELECT * FROM USER WHERE UPPER(U.NAME) = 'STEVEN'

Have a look at using 看看使用

UPPER and LOWER UPPERLOWER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM