问题
When working with MySQL, how can I fetch all rows where the name column is all uppercase?
Since equality is case insensitive, I'm not quite sure how to do this.
回答1:
If your column collation is case insensitive, you can override it in your query:
SELECT * FROM my_table WHERE my_column COLLATE latin1_bin = UPPER(my_column);
COLLATE clause syntax.
回答2:
SELECT * FROM my_table REGEXP '^[[:upper:]]+$';
回答3:
SELECT * FROM table where binary your_field REGEXP '^[[:upper:]]+$'
Similarly:
SELECT * FROM table where binary your_field REGEXP '^[[:upper:]]+$'
The 'binary' casts the field to binary which is necessary for REGEXP to be case-sensitive with most data types (except binary, of course).
[:character_class:] notation is documented here - there are several other useful character classes.
'binary' operator is documented here.
来源:https://stackoverflow.com/questions/1467589/finding-all-caps-in-columns