gpt4 book ai didi

java - 在 Oracle 和 H2 中的 @Formula 中使用 CURRENT_DATE()

转载 作者:行者123 更新时间:2023-12-01 19:30:18 25 4
gpt4 key购买 nike

我之前的问题因重复而被关闭

Use sysdate in @Formula in Oracle and H2

建议的解决方案:

How to use current date in H2 database SQL query

我已经尝试过CURRENT_TIMESTAMP:

@Formula("FLOOR(CURRENT_TIMESTAMP() - last_date)")
private Long daysSinceLastDate;

它正在与嵌入式 H2 数据库进行集成测试,但正在运行应用程序 Oracle:

Caused by: java.sql.SQLException: ORA-30088: datetime/interval precision is out of range

CURRENT_TIMESTAMP() 在 Oracle 中根本不起作用,并且 CURRENT_TIMESTAMP 在 H2 中不起作用。

最佳答案

我在 @Where 子句中遇到了同样的问题。我需要类似的东西

@Entity
@Where(clause = "open_date <= current_date")
public class SomeEntity {

// omitted

}

由于 Oracle 和 H2 都有具有 current_timestamp 输入精度的函数,因此

@Entity
@Where(clause = "open_date <= current_timestamp(6)")
public class SomeEntity {

// omitted

}

为我工作。这里的6是默认值,因此相当于Oracle中的current_timestamp和H2中的current_timestamp()

关于java - 在 Oracle 和 H2 中的 @Formula 中使用 CURRENT_DATE(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59265020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com