Spring Boot Data JPA: Oracle error:- ORA-01867: the interval is invalid

Spring Boot Data JPA: Oracle error:- ORA-01867: the interval is invalid

对于下面的查询,我得到一个错误,ORA-01867:间隔无效

  @Query(value="select * from Customer s where s.CUS_ID=:customerid and s.INSERT_TM < systimestamp - INTERVAL ':threshold' MINUTE", nativeQuery=true)
    @List<Customers> getCustomers(@Param("customerid") String customerid, @Param("threshold") Integer threshold )

此语句有误

INTERVAL ':threshold' MINUTE

但是如果我对阈值字段进行硬编码,那么我会得到成功响应,

INTERVAL '5' MINUTE

我不想硬编码。谁能告诉我如何解决这个问题?

您可能需要像下面这样使用以下技巧来使其工作:

@Query"select * from Customer s where s.CUS_ID=:customerid and s.INSERT_TM < systimestamp - :threshold*INTERVAL '1' MINUTE"
 @List<Customers> getCustomers(@Param("customerid") String customerid, @Param("threshold") String threshold )

为了证明乘法适用于区间,你可以检查这个fiddle