【发布时间】:2023-03-29 11:40:01
【问题描述】:
在 JPQL 中如何表达如下 SQL:
select * from table where
( ( table.col1 , table.col2) in
(col1val1, col2val1),
(col1val2, col2val2),
(col1val3, col2val3)
)
顺便说一句:以上是有效的 Oracle SQL 语法
【问题讨论】:
在 JPQL 中如何表达如下 SQL:
select * from table where
( ( table.col1 , table.col2) in
(col1val1, col2val1),
(col1val2, col2val2),
(col1val3, col2val3)
)
顺便说一句:以上是有效的 Oracle SQL 语法
【问题讨论】:
我的 JPQL 很糟糕,但是如何:
select tableDto from TableDto tableDto
where (tableDto.col1 = col1val1 and tableDto.col2 = col2val1)
or (tableDto.col1 = col1val2 and tableDto.col2 = col2val2)
or (tableDto.col1 = col1val3 and tableDto.col2 = col2val3)
不好看。
【讨论】:
编辑:忘记下面的内容,这是不正确的。留下来展示想法
我认为您首先必须将多维语句拆分为其组成部分:
select * from table
where table.col1 in (col1val1, col1val2, col1val3)
and table.col2 in (col2val1, col2val2, col2val3)
这将在 JPQL 中翻译(假设“表”映射到实体 TableDto),如下所示:
select tableDto from TableDto tableDto
where tableDto.col1 in(col1val1, col1val2, col1val3)
and tableDto.col2 in(col2val1, col2val2, col2val3)
以上内容未经测试,但可以在JPQL reference documentation中找到更多信息。
【讨论】: