@@ -1473,17 +1473,17 @@ public String getLimitString() {
1473
1473
if (count <= 0 || RequestMethod .isHeadMethod (getMethod (), true )) {
1474
1474
return "" ;
1475
1475
}
1476
- return getLimitString (getPage (), getCount (), isOracle () || isSQLServer () || isDb2 ());
1476
+ return getLimitString (getPage (), getCount (), isOracle () || isSQLServer () || isDb2 (), isOracle () );
1477
1477
}
1478
1478
/**获取限制数量
1479
1479
* @param limit
1480
1480
* @return
1481
1481
*/
1482
- public static String getLimitString (int page , int count , boolean isTSQL ) {
1482
+ public static String getLimitString (int page , int count , boolean isTSQL , boolean isOracle ) {
1483
1483
int offset = getOffset (page , count );
1484
1484
1485
- if (isTSQL ) { // OFFSET FECTH 中所有关键词都不可省略
1486
- return " OFFSET " + offset + " ROWS FETCH FIRST " + count + " ROWS ONLY" ;
1485
+ if (isTSQL ) { // OFFSET FECTH 中所有关键词都不可省略, 另外 Oracle 数据库使用子查询加 where 分页
1486
+ return isOracle ? " WHERE ROWNUM BETWEEN " + offset + " AND " + ( offset + count ): " OFFSET " + offset + " ROWS FETCH FIRST " + count + " ROWS ONLY" ;
1487
1487
}
1488
1488
1489
1489
return " LIMIT " + count + (offset <= 0 ? "" : " OFFSET " + offset ); // DELETE, UPDATE 不支持 OFFSET
@@ -2613,8 +2613,12 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
2613
2613
2614
2614
config .setPreparedValueList (new ArrayList <Object >());
2615
2615
String column = config .getColumnString ();
2616
- return explain + "SELECT " + (config .getCache () == JSONRequest .CACHE_RAM ? "SQL_NO_CACHE " : "" ) + column + " FROM " + getConditionString (column , tablePath , config );
2617
- }
2616
+ if (config .isOracle ()){
2617
+ //When config's database is oracle,Using subquery since Oracle12 below does not support OFFSET FETCH paging syntax.
2618
+ return explain + "SELECT * FROM (SELECT" + (config .getCache () == JSONRequest .CACHE_RAM ? "SQL_NO_CACHE " : "" ) + column + " FROM " +getConditionString (column , tablePath , config )+ ") " +config .getLimitString ();
2619
+ }else
2620
+ return explain + "SELECT " + (config .getCache () == JSONRequest .CACHE_RAM ? "SQL_NO_CACHE " : "" ) + column + " FROM " + getConditionString (column , tablePath , config );
2621
+ }
2618
2622
}
2619
2623
2620
2624
/**获取条件SQL字符串
@@ -2641,7 +2645,7 @@ private static String getConditionString(String column, String table, AbstractSQ
2641
2645
2642
2646
//no need to optimize
2643
2647
// if (config.getPage() <= 0 || ID.equals(column.trim())) {
2644
- return condition + config .getLimitString ();
2648
+ return config . isOracle ()? condition : condition + config .getLimitString ();
2645
2649
// }
2646
2650
//
2647
2651
//
0 commit comments