如何在“like”子句中转义通配符?

问题描述 投票:8回答:1

如何在like子句中转义通配符?

例如:

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 hql wildcard
1个回答
12
投票

在Hibernate 3中,您可以使用escape参数指定转义字符:

select foo from Foo as foo where foo.bar like '!%' escape '!'

我认为这应该有效,尽管我从未在实践中尝试过。

© www.soinside.com 2019 - 2024. All rights reserved.