Comparing strings with one having empty spaces before while the other does not

前端 未结 2 1891
清歌不尽
清歌不尽 2020-12-10 18:48

If I have to find a string name \"Akito\" and it lies in the table foo then following is the normal procedure,

select * from foo where `name = \         


        
2条回答
  •  臣服心动
    2020-12-10 19:11

    http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html says the following:

    In particular, trailing spaces are significant, which is not true for CHAR or VARCHAR comparisons performed with the = operator:

    mysql> SELECT 'a' = 'a ', 'a' LIKE 'a ';
    +------------+---------------+
    | 'a' = 'a ' | 'a' LIKE 'a ' |
    +------------+---------------+
    |          1 |             0 |
    +------------+---------------+
    1 row in set (0.00 sec)
    

    Trailing means not leading. Those seem to be relevant.

提交回复
热议问题