JPA concat operator

后端 未结 3 730
青春惊慌失措
青春惊慌失措 2020-12-30 20:11

Is there a JPA concat operator for string concatenation?

I know there is a JPA CONCAT function, however its ugly to use for concatenating multiple strin

相关标签:
3条回答
  • 2020-12-30 20:44

    The CONCAT function was extended in JPA 2.0 to allow passing more than 2 parameters, from section 4.6.17.2.1 (String Functions) of the specification:

    CONCAT(string_primary, string_primary {, string_primary}* )
    

    In JPA 1 this was restricted to exactly two parameters.

    0 讨论(0)
  • 2020-12-30 20:45

    You can also use || as a concatenate operator, see on the documentation

    HQL defines a concatenation operator in addition to supporting the concatenation (CONCAT) function. This is not defined by JPQL, so portable applications should avoid it use. The concatenation operator is taken from the SQL concatenation operator - ||.

    Example 11.19. Concatenation operation example

    select 'Mr. ' || c.name.first || ' ' || c.name.last
    from Customer c
    where c.gender = Gender.MALE
    
    0 讨论(0)
  • 2020-12-30 21:04

    You can use JPA Concat function for multiple strings.

    For example:

    CONCAT(cola, colb, colc, cold)
    
    0 讨论(0)
提交回复
热议问题