How to check for uppercase letters in MySQL?

牧云@^-^@ 提交于 2019-11-30 12:39:58

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.

For me this works and is not using a regexp. It basically compares the field with itself uppercased by mysql itself.

-- will detect all names that are not in uppercase
SELECT 
    name, UPPER(name) 
FROM table 
WHERE 
    BINARY name <> BINARY UPPER(name)
;

change to case sensitive collation, eg.

CHARACTER SET latin1 COLLATE latin1_general_cs

then try this query,

SELECT 'z' REGEXP '^[A-Z]+$'

This worked for me to get the list of rows having only upper case characters:

SELECT 
    name, UPPER(name) 
FROM table 
WHERE 
    BINARY name = BINARY UPPER(name)
;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!