Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for uppercase letters in MySQL?

Tags:

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:]]+$'; 

This gives true, although the z is in lower case,... why?

like image 569
R_User Avatar asked May 15 '13 07:05

R_User


People also ask

How can I get uppercase name in SQL?

The UPPER() function converts a string to upper-case.

How do you find lowercase and uppercase in SQL?

Case insensitive SQL SELECT: Use upper or lower functionsselect * from users where lower(first_name) = 'fred'; As you can see, the pattern is to make the field you're searching into uppercase or lowercase, and then make your search string also be uppercase or lowercase to match the SQL function you've used.

How do I capitalize a letter in MySQL?

If you want to upper-case the first letter and lower-case the other, you just have to use LCASE function : UPDATE tb_Company SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), LCASE(SUBSTRING(CompanyIndustry, 2))); Note that UPPER and UCASE do the same thing.


2 Answers

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.

like image 71
Kyle Anderson Avatar answered Oct 04 '22 10:10

Kyle Anderson


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) ; 
like image 20
Elzo Valugi Avatar answered Oct 04 '22 09:10

Elzo Valugi