Why does “_” (underscore) match “-” (hyphen)?

后端 未结 2 1116
陌清茗
陌清茗 2020-12-07 14:16

I have to look for a PDF manual using this query:

root@localhost:test> select * from a where name like \'%taz_manual%.pdf%\';
+--------------------+------         


        
2条回答
  •  攒了一身酷
    2020-12-07 15:00

    I had a similar issue with space and hyphens while matching strings with exact match:

    SELECT id FROM location WHERE name = 'IND - HQ';
    

    The above query didn't return any records in MySQL. I had to escape the spaces and hyphens and use LIKE instead of exact match with equals (=) as follows:

    SELECT id FROM location WHERE name LIKE 'IND_\-_HQ';
    

提交回复
热议问题