java HQL 中的 between 是否严格比较?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/586077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 12:57:56  来源:igfitidea点击:

Does between in HQL compare strictly or not?

javahibernatejpahql

提问by flybywire

if I write in HQL

如果我用 HQL 编写

A between 5 and 10

is that equivalent to

这相当于

A >= 5 and A <= 10

or

或者

A > 5 and A < 10

or some other of the 4 combinations?

还是其他 4 种组合?

回答by Dan Berindei

I didn't find any specification of the behavior in the Hibernate docs, but the betweenoperator in HQL is translated to the betweenoperator in SQL, which is inclusive.

我在 Hibernate 文档中没有找到任何行为规范,但是betweenHQL 中的操作符被转换为betweenSQL 中的操作符,这是包含性的。

So betweenin HQL is also inclusive, that is

所以between在HQL中也是包容的,就是

A between 5 and 10

is equivalent to

相当于

A >= 5 and A <= 10

回答by Andreas Petersson

obviously there is some confusion regarding this. natural language would suggest it is exclusive, but this is not true. in reality its A >= 5 and A<=10. since there were already contradicting answers given (and delted), there needs to be more clarification: (from http://www.techonthenet.com/sql/between.php)

显然,对此存在一些混淆。自然语言会暗示它是排他性的,但事实并非如此。实际上它的 A >= 5 和 A<=10。由于已经给出(和删除)相互矛盾的答案,需要更多说明:(来自http://www.techonthenet.com/sql/between.php

Example #1 - Numbers

The following is an SQL statement that uses the BETWEEN function:

SELECT *
FROM suppliers
WHERE supplier_id between 5000 AND 5010;

This would return all rows where the supplier_id is between 5000 and 5010, inclusive. It is equivalent to the following SQL statement:

SELECT *
FROM suppliers
WHERE supplier_id >= 5000
AND supplier_id <= 5010;