本文介绍了用jOOQ间隔执行date_sub()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从昨天开始,我一直在处理这个问题.

I've been dealing with this since yestertay.

问题是我将查询迁移到 jOOQ ,当我尝试实现这一部分时遇到了麻烦:

The thing is I am migrating my queries to jOOQ and I got stuck when I tried to implement this part:

select * from table where condition1 and date1 >= date_sub(now(), interval 1 days)

具体来说,这部分情况是: date_sub(now(),间隔1天),带有jOOQ.

Specifically this part of the condition: date_sub(now(), interval 1 days) with jOOQ.

所以我的问题是:

  1. 我应该从jOOQ中使用哪些函数来表示date_sub?

  1. Which functions should I use from jOOQ to represent date_sub?

如何使用jOOQ实施间隔X天?

How do I implement interval X days with jOOQ?

为明确起见,日期的类型为时间戳

To clarify, the dates are of the type Timestamp

提前谢谢!

推荐答案

解决方案:

jOOQ略微偏向Oracle数据库,只需使用以下命令即可实现增加/减少日间隔:

The solution:

Being slightly biased towards the Oracle database, jOOQ implements adding / subtracting day intervals simply by using:

// Java
DSL.currentTimestamp().sub(1);

以上呈现:

-- Oracle
sysdate - 1

-- MySQL
date_add(current_timestamp(), interval -1 day)

当然,您也可以访问 date_add() 直接运行,如果您愿意的话:

Of course, you can also access the date_add() function directly, if you prefer that:

// Java
DSL.dateAdd(DSL.currentTimestamp(), -1);

一些文档:

10-14 05:10