DB Pagination
不同的DB的分页方式存在差异,
https://en.wikipedia.org/wiki/Select_(SQL)#FETCH_FIRST_clause
https://stackoverflow.com/questions/67036621/oracle-dialect-for-pagination
另外JPA的Pageable是支持Oracle的,但有时需要设置方言:
针对错误:java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束
因为oracle不支持limit的用法,需要在application.properties增加以下配置
#hibernate数据库方言配置:
#org.hibernate.dialect.Oracle9iDialect,org.hibernate.dialect.Oracle10gDialect,org.hibernate.dialect.Oracle12cDialect;
10、11都使用org.hibernate.dialect.Oracle10gDialect
12使用org.hibernate.dialect.Oracle12cDialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
增加配置后,输出的sql为:select X from X where X fetch first ? rows only;
// offset is un-contained. eg: for 1 ~ 10 offset 2 rows fetch first 5 rows only
while return 3 ~ 7
OFFSET %d ROWS FETCH FIRST %d ROWS ONLY
// 针对Oracle12,还可以用下面这种形式。建议用上面这种standard
OFFSET %d ROWS FETCH NEXT %d ROWS ONLY