11.4.14. 関係比較について
比較には比較演算子 ( =, >, >=, <, <=, <>]>) の1 つが関与します。また、HQL は <![CDATA[<> の比較演算子の同義として != を定義します。演算対象は同じ型でなければなりません。
例11.17 関係比較の例
// numeric comparison select c from Customer c where c.chiefExecutive.age < 30 // string comparison select c from Customer c where c.name = 'Acme' // datetime comparison select c from Customer c where c.inceptionDate < {d '2000-01-01'} // enum comparison select c from Customer c where c.chiefExecutive.gender = com.acme.Gender.MALE // boolean comparison select c from Customer c where c.sendEmail = true // entity type comparison select p from Payment p where type(p) = WireTransferPayment // entity value comparison select c from Customer c where c.chiefExecutive = c.chiefTechnologist
比較には、サブクエリ限定子である
ALL
、 ANY
、 SOME
も関与します。SOME
と ANY
は同義です。
サブクエリの結果にあるすべての値に対して比較が true である場合、
ALL
限定子は true に解決されます。サブクエリの結果が空の場合は false に解決されます。
例11.18 ALL サブクエリ比較限定子の例
// select all players that scored at least 3 points // in every game. select p from Player p where 3 > all ( select spg.points from StatsPerGame spg where spg.player = p )
サブクエリの結果にある値の一部 (最低でも 1 つ) に対して比較が true の場合、
ANY
または SOME
限定子は true に解決されます。サブクエリの結果が空である場合、false に解決されます。