Question

I am wondering if there is something like the CONCAT_WS method in JPQL as I found it in the MYSQL documentation here:

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws

Anyone ever stumbled over anything comparable?

Was it helpful?

Solution

No, there is not. JPQL does have following String functions: CONCAT, LENGTH, LOWER, SUBSTRING, TRIM, and UPPER. Only way in with older JPQL versions is to simply repeat separator between each value in CONCAT:

SELECT CONCAT(se.string1, ';', se.string2) 
FROM SomeEntity se

With JPQL in the JPA 2.1 specification implementations it is possible to call database functions as follows (first arguments is name of the function, others are arguments to function):

SELECT FUNCTION('CONCAT_WS', ';', se.string1, se.string2) 
FROM SomeEntity se

Older EclipseLink versions have same functionality via FUNC keyword.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top