简体   繁体   English

JPQL 中的 select 语句中的 Substring

[英]Substring in select statement in JPQL

I'm trying to select a substring of column, ie select substring(description, 1, 200) from category where id=1我正在尝试select列的substring ,即select substring(description, 1, 200) from category where id=1

Is it possible to have a substring function within a select statement in JPQL/JPA 2?是否可以在 JPQL/JPA 2 的 select 语句中包含 substring function? If yes, how?如果是,如何? If no, are there any alternatives?如果没有,是否有其他选择? Thanks.谢谢。

There is a scalar expression for this: SUBSTRING(string, start, end) 有一个标量表达式: SUBSTRING(string,start,end)

I believe this is allowed in the SELECT clause in JPA 2.0, but not in JPA 1.0. 我相信JPA 2.0中的SELECT子句允许这样做,但JPA 1.0中不允许。

I'm afraid there is not such function yet. 恐怕还没有这样的功能。 There is a substring function but can only be used in the WHERE part of your query. 有一个子字符串函数,但只能在查询的WHERE部分中使用。

Your most simple alternative would be to invoke the String class substring method for each row. 您最简单的选择是为每一行调用String类的子字符串方法。

Hope this helps! 希望这可以帮助!

Regards, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM