2011-07-24 100 views
1

我正试图通过phpmyadmin在我的数据库中搜索任何包含%20的行。这里是我的查询:在mySQL数据库中搜索%20

select * from `jos_picmicro_content` where `introtext` like '\%20' escape '\'; 

除了它返回以下错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\'' at line 1 

我做了什么错?

回答

5

您已逃脱'。正确的语法是:

select * from `jos_picmicro_content` where `introtext` like '\%20' escape '\\'; 

为了快速识别问题,将您的查询到不同的行,例如:

select * from `jos_picmicro_content` 
where `introtext` 
like '\%20' 
escape '\\'; 

那么MySQL会提醒在哪一行的问题。

2

这可能与MySQL的非标准使用\字符有关。但是,你可以指定任何字符ESCAPE关键字:

select * 
from jos_picmicro_content 
where introtext like '@%20' escape '@'; 

但是,这仍然不会返回高于行,其中introtext是正是'%20'其他anyhting,你仍然需要使用通配符来找到%20任何地方在该列:

select * 
from jos_picmicro_content 
where introtext like '%@%20%' escape '@'; 
0

,因为MySQL默认转义字符是“\”您可以删除您的查询的escape '\';一部分。但是,如果你真的需要escape部分,那么你必须输入它:

escape '\\'; 

或者

escape '\\\\'; 
0

你尝试简单:

SELECT * FROM jos_picmicro_content其中introtext LIKE“%\ %20%'