简体   繁体   中英

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

Is it possible to have a substring function within a select statement in JPQL/JPA 2? If yes, how? If no, are there any alternatives? Thanks.

There is a scalar expression for this: SUBSTRING(string, start, end)

I believe this is allowed in the SELECT clause in JPA 2.0, but not in 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.

Your most simple alternative would be to invoke the String class substring method for each row.

Hope this helps!

Regards,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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