If someone passes a '%'
to a field that compares in my sql with su.username LIKE CONCAT('%', email ,'%'))
it returns all rows. It ends up looking like su.username LIKE CONCAT('%%%')
. Can I get around this in anyway without filtering out the '%'
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I'm assuming you mean you want to escape the %
so it matches a literal %
instead of anything.
In that case, you just need:
... su.username LIKE CONCAT('%',REPLACE(email,'%','\\%'),'%')
回答2:
You need to escape the %, so it literally matches '%'
select * from mytable
where mycol like '%\%%';