如何在“like”中转义通配符HQL中的子句? [英] How to escape wildcard characters in "like" clause in HQL?
本文介绍了如何在“like”中转义通配符HQL中的子句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
如何在类似的子句中转义通配符?
从foo中选择foo作为foo,其中foo.bar就像'%'|| :filter ||'%'
query.setParameter(filter,%);
query.list();
//我希望能得到包含'%'的foo,而不是所有的!
有什么想法?
解决方案
在Hibernate 3中,您可以使用escape参数来指定转义字符:
select foo from Foo as foo where foo.bar like '!%'escape'!'
我认为应该可以,尽管我从来没有尝试过练习。
How can I escape the wildcard characters in a like clause?
E.g.:
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!
Any ideas?
解决方案
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.
这篇关于如何在“like”中转义通配符HQL中的子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文