简体   繁体   English

JPA concat运营商

[英]JPA concat operator

Is there a JPA concat operator for string concatenation? 是否有用于字符串连接的JPA concat运算符?

I know there is a JPA CONCAT function, however its ugly to use for concatenating multiple strings. 我知道有一个JPA CONCAT函数,但它用于连接多个字符串很难看。

CONCAT(CONCAT(CONCAT(cola,colb),colc),cold)

Vendors like Oracle offer || 像Oracle这样的供应商提供了|| some other like Microsoft offer + . 其他一些像微软提供+ Is there a standard JPA concatenation operator so that I could create a query like 是否有标准的JPA连接运算符,以便我可以创建一个类似的查询

cola || colb || colc || cold

I tried + using openjpa with SQL Server, however it seems to be invalid JPQL. 我试图+将OpenJPA与SQL Server,但它似乎是无效的JPQL。 I couldn't find anything regarding such an operator in an oracle reference . 我在oracle参考中找不到关于这样的运算符的任何内容。

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函数在JPA 2.0中进行了扩展,允许从规范的4.6.17.2.1节(字符串函数)传递2个以上的参数:

CONCAT(string_primary, string_primary {, string_primary}* )

In JPA 1 this was restricted to exactly two parameters. 在JPA 1中,这仅限于两个参数。

You can use JPA Concat function for multiple strings. 您可以将JPA Concat函数用于多个字符串。

For example: 例如:

CONCAT(cola, colb, colc, cold)

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. 除了支持串联(CONCAT)功能之外,HQL还定义了连接运算符。 This is not defined by JPQL, so portable applications should avoid it use. 这不是由JPQL定义的,因此便携式应用程序应该避免使用它。 The concatenation operator is taken from the SQL concatenation operator - ||. 连接运算符取自SQL连接运算符 - ||。

Example 11.19. 例11.19。 Concatenation operation example 连接操作示例

 select 'Mr. ' || c.name.first || ' ' || c.name.last from Customer c where c.gender = Gender.MALE 

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

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