Is it possible to get partitioned data using SQL?
<p>I have a RDBMS table with a column <code>BIGINT</code> type and values are not sequential. I have a java program where I want each thread to get data as per <code>PARTITION_SIZE</code> i.e. I want a pair of column values like after doing <code>ORDER BY</code> on result, </p>

<pre><code>Column_Value at Row 0 , Column_Value at Row `PARTITION_SIZE` 

Column_Value at Row `PARTITION_SIZE+1` , Column_Value at Row `2*PARTITION_SIZE` 

Column_Value at Row `2*PARTITION_SIZE+1` , Column_Value at Row  `3*PARTITION_SIZE`
</code></pre>

<p>Eventually, I will pass above value ranges  in a SELECT query's <code>BETWEEN</code> clause to get divided data for each thread. </p>

<p>Currently, I am able to do this partitioning via Java by putting all values in a <code>List</code> ( after getting all values from DB ) and then getting values at those specific indices - <code>{0,PARTITION_SIZE},{PARTITION_SIZE+1,2*PARTITION_SIZE}</code> ..etc but problem there is that <code>List</code> might have millions of records and is not advisable to store in memory. </p>

<p>So I was wondering if its possible to write such a query using SQL itself which would return me those ranges like below?</p>

<blockquote>
  <p>row-1 -> minId , maxId </p>
  
  <p>row-2 -> minId , maxId</p>
  
  <p>....</p>
</blockquote>

<p>Database is DB2.</p>

<p>For example,</p>

<p>For table column values <code>1,2,12,3,4,5,20,30,7,9,11</code>  ,result of SQL query for a <strong>partition size =2</strong> should be <code>{1,2},{3,4} ,{5,7},{9,11},{12,20},{30}</code> . </p>