如何以“喜欢"方式转义通配符条款? [英] How to escape wildcard characters in "like" clause?
本文介绍了如何以“喜欢"方式转义通配符条款?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在like子句中转义通配符?
How can I escape the wildcard characters in a like clause?
例如:
select foo from Foo as foo where foo.bar like '%' || :filter ||'%'
query.setParameter("filter", "%");
query.list();
// I'd expect to get the foo's containing the '%' in bar, not all of them!
有什么想法吗?
推荐答案
在Hibernate 3中,您可以使用escape参数指定转义字符:
In Hibernate 3 you can use the escape parameter to specify the escape char:
select foo from Foo as foo where foo.bar like '!%' escape '!'
尽管我从未在实践中尝试过,但我认为这应该可行.
I think that should work, although I have never tried it in practice.
这篇关于如何以“喜欢"方式转义通配符条款?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文