如何在MySQL中检查大写字母? [英] How to check for uppercase letters in MySQL?
本文介绍了如何在MySQL中检查大写字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查字符串是否仅包含大写字母.我知道RLIKE/REGEXP在MySQL中不区分大小写.所以我尝试使用:upper:
字符类:
I want to check, if a string consits only of uppercase letters. I know that RLIKE/REGEXP are not case sensitive in MySQL. So I tried to use the :upper:
character class:
SELECT 'z' REGEXP '^[[:upper:]]+$';
这是正确的,尽管z是小写,...为什么?
This gives true, although the z is in lower case,... why?
推荐答案
REGEXP不区分大小写,除非与二进制字符串一起使用.
REGEXP is not case sensitive, except when used with binary strings.
http://dev.mysql.com/doc/refman/5.7/en/regexp.html
因此请记住,只需执行以下操作:
So with that in mind, just do something like this:
SELECT * FROM `users` WHERE `email` REGEXP BINARY '[A-Z]';
使用上面的示例,您将获得包含一个或多个大写字母的电子邮件列表.
Using the above example, you'd get a list of emails that contain one or more uppercase letters.
这篇关于如何在MySQL中检查大写字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文