问题描述
从昨天开始,我一直在处理这个问题.
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.
所以我的问题是:
-
我应该从jOOQ中使用哪些函数来表示date_sub?
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);
一些文档:
- 手册中有关日期的部分时间算术
- 手册中有关间隔的部分数据类型
-
Field.add()
Javadoc -
DSL.dateAdd()
Javadoc - The manual's section about date time arithmetic
- The manual's section about interval data types
Field.add()
JavadocDSL.dateAdd()
Javadoc
Some documentation:
这篇关于用jOOQ间隔执行date_sub()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!