我有一个 SQL 数据库,我想做一个显示所有包含符号“%”的数据的查询。通常,要在数据库中查找字符(例如:“z”),我会使用如下查询:
mysql_query("SELECT * FROM mytable WHERE tag LIKE '%z%'");
但在这里,我想找到 % 字符,但在 SQL 中它是一个 clown ,所以当我写:
mysql_query("SELECT * FROM mytable WHERE tag LIKE '%%%'");
它显示了我所有的数据。那么如何在我的 SQL 数据中找到 % 字符呢?
谢谢
最佳答案
您可以使用反斜杠转义 %
符号:
SELECT * FROM mytable WHERE tag LIKE '%\%%'
引自MySQL 5.0 Reference Manual :: 8.1.1 String小号:
The
\%
and\_
sequences are used to search for literal instances of%
and_
in pattern-matching contexts where they would otherwise be interpreted as wildcard characters.
关于php - 在 LIKE 查询中查找 % 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2890220/