code: public static String getLimitSQL(String query, long offset, long length, String dbType) {
  		if (query == null) {
  			return null;
  		}
  		query = query.trim();
  		if (StringUtils.startsWithIgnoreCase(query, "select")) {
  			boolean isForUpdate = false;
  			if (query.toLowerCase().endsWith(" for update")) {
  				query = query.substring(0, query.length() - 11);
  				isForUpdate = true;
  			}
  
  			StringBuffer pagingSelect = new StringBuffer(query.length() + 100);
  			if (dbType.equalsIgnoreCase("oracle")) {
  				if (offset > 0) {
  					pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
  				} else {
  					pagingSelect.append("select * from ( ");
  				}
  				pagingSelect.append(query);
  				if (offset > 0) {
  					pagingSelect.append(String.format(" ) row_ where rownum <= %d) where rownum_ > %d", length + offset, offset));
  				} else {
  					pagingSelect.append(String.format(" ) where rownum <= %d", length));
  				}
  			} else if (dbType.equalsIgnoreCase("mysql")) {
  				pagingSelect.append("select * from ( ");
  				pagingSelect.append(query);
  				pagingSelect.append(String.format(" ) t limit %d, %d", offset, length));
  			}
  
  			if (isForUpdate) {
  				pagingSelect.append(" for update");
  			}
  
  			return pagingSelect.toString();
  		}
  		return query;
  	}
docs: 限制查询条数的SQL
  
  @param query SQL语句
  @param offset SQL查询偏移记录数
  @param length SQL目标数量
  @param dbType 数据库类型 oralce ,mysql
  
  @return 限制查询条数的SQL