LIMIT打破@Query

时间:2019-03-14 16:05:07

标签: java sql oracle hibernate jpa

所以...

以下查询

@Query(value = "SELECT A, B ... FROM ADMIN.SUPER_SEARCH WHERE A = :param OR B = :param ORDER BY A desc", nativeQuery = true )

将正常工作(我用...替换了几个字段,这是一个很长的查询)

但是一旦我在查询末尾添加LIMIT 5,它将抛出

Caused by: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

这是错误查询

@Query(value = "SELECT A, B ... FROM ADMIN.SUPER_SEARCH WHERE A = :param OR B = :param ORDER BY A desc LIMIT 5", nativeQuery = true )

为什么?

我真的需要这里的限制,因为表长约30万行。

1 个答案:

答案 0 :(得分:2)

尝试:

@Query(value = "SELECT A, B ... FROM ADMIN.SUPER_SEARCH WHERE A = :param OR B = :param AND rownum <= 5 ORDER BY A desc", nativeQuery = true )