[英]How to find all upper case strings in a MySQL table?
I initially thought this is trivial. 我最初认为这是微不足道的。 Then thought 'binary' might do it. 然后认为'二进制'可能会这样做。 I am unsure at this point. 我不确定这一点。
Name
----
John
MARY
Kin
TED
I would like to query just MARY and TED which are in all upper case. 我想查询MARY和TED,它们都是大写的。 How would I query this? 我该如何查询?
You just use the UPPER() function on the Name
field and compare the results with the original value of Name
: 您只需在Name
字段中使用UPPER()函数,并将结果与Name
的原始值进行比较:
select Name from Table where Name = UPPER(Name)
This way 这条路
UPPER(Name) || Name
---------------------------------------
JOHN != John
MARY == MARY
KIN != Kin
TED == TED
only the rows you need will be returned. 只返回您需要的行。
As @mdoyle commented here, you should define the column with the right collation (case sensitive), otherwise as others did answer you need the BINARY operator to compare case insensitive columns. 正如@mdoyle在这里评论的那样,您应该使用正确的排序规则定义列(区分大小写),否则当其他人确实回答时,您需要使用BINARY运算符来比较不区分大小写的列。
试试这个:
select name from table where name=upper(name);
Try this: 试试这个:
SELECT Name
FROM table
WHERE Name COLLATE latin1_general_cs LIKE UPPER(Name)
;
使用下面:
SELECT name FROM table WHERE name = BINARY UPPER(column_name);
This will also return numeric values, but that doesnt look to be an issue for your column name. 这也将返回数值,但这看起来不是您的列名的问题。
SELECT * FROM names WHERE
ASCII(name) = ASCII(Upper(name))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.