code: static String buildSelectChunkSql(String databaseType, String table, long start, int length, String columns, String[] columnNames) {
  
      String sqlText = "SELECT " + columns + " FROM " + table;
      switch(databaseType) {
        case SQL_SERVER_DB_TYPE:  // requires ORDER BY clause with OFFSET/FETCH NEXT clauses, syntax supported since SQLServer 2012
          sqlText += " ORDER BY ROW_NUMBER() OVER (ORDER BY (SELECT 0))";
          sqlText += " OFFSET " + start + " ROWS FETCH NEXT " + length + " ROWS ONLY";
          break;
  
        case ORACLE_DB_TYPE:
          sqlText += " OFFSET " + start + " ROWS FETCH NEXT " + length + " ROWS ONLY";
          break;
  
        case TERADATA_DB_TYPE:
          sqlText += " QUALIFY ROW_NUMBER() OVER (ORDER BY " + columnNames[0] + ") BETWEEN " + (start+1) + " AND " + (start+length);
          break;
  
        default:
          sqlText += " LIMIT " + length + " OFFSET " + start;
      }
  
      return sqlText;
    }
docs: Builds SQL SELECT to retrieve chunk of rows from a table based on row offset and number of rows in a chunk.
  
  Pagination in following Databases:
  SQL Server, Oracle 12c: OFFSET x ROWS FETCH NEXT y ROWS ONLY
  SQL Server, Vertica may need ORDER BY
  
  MySQL, PostgreSQL, MariaDB: LIMIT y OFFSET x
  
  Teradata (and possibly older Oracle):
  SELECT * FROM mytable
  QUALIFY ROW_NUMBER() OVER (ORDER BY column_name) BETWEEN x and x+y;
  
  @param databaseType
  @param table
  @param start
  @param length
  @param columns
  @param columnNames array of column names retrieved and parsed from single row SELECT prior to this call
  @return String SQL SELECT statement