Given the following Oracle sql query cooked for a PreparedStatement:
SELECT *
FROM my_table
WHERE field1 = 'foo'
and field2 =ANY (substr( ? , 1, 2) || '00000000',
substr( ? , 1, 4) || '000000',
substr( ? , 1, 6) || '0000',
substr( ? , 1, 8) || '00',
?
)
I want to translate to a JPQL query. Reading the JPQL doc, substr becomes substring
and ANY stays as it is. In JPQL ANY expects a subquery.
How can I change the list into a subquery ? or should I use IN operator or should I generate a JPQL string with a bunch of OR conditions in it ?
Oracle 10gR2
Java 5
JPA 2
Considering that
= ANY(...)is equivalent toIN (...)in SQL, you can safely use IN.In fact, the
INpredicate is defined in terms of theANYpredicate. Excerpt of the SQL 1992 standard:Then again, the
ANY/SOME<quantified comparison predicate>operators are defined in a way similar to a bunch ofORconnected predicates. Hence the answer is: You can use bothINorOR-connected predicates.Note: While this answer explains things how they are in SQL, I’m pretty sure something similar applies to JPQL as well.