gpt4 book ai didi

php - 在 LIKE 查询中查找 % 字符

转载 作者:行者123 更新时间:2023-11-29 01:07:37 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com