在 QueryDSL / Oracle SQL 中是否有一个干净的解决方案来实现包含开始、排他结束?

Is there a clean solution to achieve inclusive start, exclusive end in QueryDSL / Oracle SQL?

我正在尝试使用 QueryDSL(包括开始日期,不包括结束日期)为时间间隔创建查询。

在QueryDSL的documentation中发现public BooleanExpression between(Expression<T> from, Expression<T> to);两边互斥,

Get a first < this < second expression

但是它转换为 Oracle SQL BETWEEN 两边都包含
(相当于 first <= this <= second)。

像这样的 QueryDSL:

[...]
person.name.like(n)
  .and(person.birthdate.between(from, to))
[...]

像这样翻译成 Oracle SQL:

SELECT *
FROM PERSON
WHERE NAME LIKE n
  AND BIRTHDATE BETWEEN from AND to;

有人知道这背后的reasons/logic吗?
它只是 'rotten' 文档吗?

很明显,两者之间对我来说都行不通。

我应该使用更笨重的

person.name.like(n)
  .and(person.birthdate.goe(from)
  .and(person.birthdate.lt(to))

或者是否有一个干净的解决方案可以满足我的要求?

这似乎只是伪劣的文档,但是,我认为这没有太大区别。如果文档按照建议进行,那么它不适合您;目前的情况稍微好一些。

Oracle 的 SQL 方言中没有一个表达式可以表示操作 first <= this < second。因此,你仍然需要做这样的事情:

person.name.like(n)
  .and(person.birthdate.between(from, to)
  .and(person.birthdate.lt(to))

在 SQL 中表示为:

select *
  from person
 where name like n
   and birthdate between from and to
   and birthdate < to

到那时,就可以很容易地预先清楚地说明您的意图并按照您的意图去做:

person.name.like(n)
  .and(person.birthdate.goe(from)
  .and(person.birthdate.lt(to))

P.S。我有点惊讶 column.like(String) 在 SQL 中变成了 column like string;这相当于 column = string。我原以为 .like() 会变成 column like string || '%',它会在列的开头搜索您要查找的字符串。

文档已经在前一段时间修复了http://www.querydsl.com/static/querydsl/2.2.0/apidocs/com/mysema/query/types/expr/ComparableExpression.html#between(T,%20T)

2.2.0 于 18.7.2011 发布。我强烈建议您使用 4.* 或 3.*.

的更新版本的 Querydsl

对于包含开始,排他结束你可以写你自己的实用方法:

public static <T> Predicate range(ComparableExpression<T> expr, T from, T to) {
    return expr.goe(expr).and(expr.lt(to));
}