MySQL 和 LIKE 与 % 的比较 [英] MySQL and LIKE comparison with %
本文介绍了MySQL 和 LIKE 与 % 的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有人将 '%'
传递给在我的 sql 中与 su.username LIKE CONCAT('%', email ,'%')) 进行比较的字段
它返回所有行.它最终看起来像 su.username LIKE CONCAT('%%%')
.我可以在不过滤掉 '%'
的情况下解决这个问题吗?
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 '%'
?
推荐答案
我假设你的意思是你想转义 %
以便它匹配文字 %
任何东西.
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,'%','\\%'),'%')
这篇关于MySQL 和 LIKE 与 % 的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文