Finding all caps in columns?

浪尽此生 提交于 2019-12-25 01:26:06

问题


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

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