How to find all upper case strings in a MySQL table?

后端 未结 6 445
执笔经年
执笔经年 2021-02-03 11:15

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 t

相关标签:
6条回答
  • 2021-02-03 11:41

    Try this:

    select name from table where name=upper(name);
    
    0 讨论(0)
  • 2021-02-03 11:54

    You just use the UPPER() function on the Name field and compare the results with the original value of 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.

    0 讨论(0)
  • Use Below:

    SELECT name FROM table WHERE name = BINARY UPPER(column_name);
    
    0 讨论(0)
  • 2021-02-03 11:59

    Try this:

    SELECT Name
    FROM   table
    WHERE  Name COLLATE latin1_general_cs LIKE UPPER(Name)
    ;
    
    0 讨论(0)
  • 2021-02-03 12:00

    If your collation is case insensitive then you need to use a BINARY comparison:

    SELECT *
    FROM yourtable
    WHERE Name = BINARY UPPER(Name)
    

    See it working online: sqlfiddle

    0 讨论(0)
  • 2021-02-03 12:02

    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))
    
    0 讨论(0)
提交回复
热议问题