[英]INTERVAL expression in Spring Data JPA Native Query
I have Spring JPA.我有 Spring JPA。
I have a query like this in sql oracle:我在 sql oracle 中有这样的查询:
SELECT * FROM MY_TABLE WHERE SYSDATE > MY_DATE + INTERVAL '10' DAY;
I have a CrudRepository in which I use the above query in native mode, like this:我有一个 CrudRepository,我在其中以本机模式使用上述查询,如下所示:
@Query(nativeQuery = true,
value = "SELECT * FROM MY_TABLE WHERE SYSDATE > MY_DATE + INTERVAL :myValue DAY")
public List<Object[]> myMethod(@Param("myValue") String myValue );
I get ORA-00933:我得到 ORA-00933:
Passing myValue as integer between quotes I get ORA-01867在引号之间将 myValue 作为 integer 传递我得到 ORA-01867
Passing myValue as integer without quotes I get ORA-00933将 myValue 作为 integer 不带引号传递我得到 ORA-00933
How to do it?怎么做?
See comments on question, there is a similar question/answer for spring/jpa/postgresql, solution for me is:查看问题评论,spring/jpa/postgresql 也有类似的问题/答案,对我来说解决方案是:
@Query(nativeQuery = true,
value = "SELECT * FROM MY_TABLE WHERE SYSDATE > MY_DATE + :myValue * (INTERVAL 1 DAY"))
public List<Object[]> myMethod(@Param("myValue") int myValue );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.