【问题标题】:How to escape wildcard characters in "like" clause?如何在“like”子句中转义通配符?
【发布时间】:2011-03-01 16:41:20
【问题描述】:

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

例如:

select foo from Foo as foo where foo.bar like '%' || :过滤器||'%' query.setParameter("filter", "%"); 查询.list(); // 我希望得到包含 bar 中的 '%' 的 foo,而不是全部!

有什么想法吗?

【问题讨论】:

    标签: hibernate hql wildcard


    【解决方案1】:

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

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

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

    【讨论】:

    • @DeanPovey 没有和我一起工作:Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: escape near line 1, column 175 [select e.id,e.title,e.type.icon,e.typeObject,e.idDomain from package.SomeClass e where ( UPPER(e.title) LIKE ?) AND e.idDomain =? escape '!' ]
    猜你喜欢
    • 1970-01-01
    • 2011-01-30
    • 2023-04-06
    • 2023-01-26
    • 1970-01-01
    • 2010-10-01
    • 2021-12-22
    相关资源
    最近更新 更多