Oracle paging idea

Paging requires two query data, the first time to obtain the total number of records, and the second time to obtain the records to be displayed.

1. Check the total number of records
if the original query statement

String sql = "select * from t1 where age > 30";

Then the statement to query the total number of records is

String sqlCount = "select count(*) from ( " + sql + ")";

The total number of records obtained is count

2. Query the required records
First define two variables

//每页记录数
int pageSize = 100
//页数
int page = 3

(Query the data on page 3, each page displays 100 rows)
Then the range of data is pageSize * (page - 1) < n <= pageSize * page, substitute the data, 200 < n <= 300, that is, 201 to 300 rows, A total of 300 records.
Then the statement to query the records that meet the conditions is

String sqlReal = "select * from (select row_.*, rownum rownum_ from ("
    + sql
    + ")row_)where 0 < rownum_ and rownum_ <= 50";//期中0和50需要用pageSize * (page - 1)和pageSize * page替换。

This implements oracle paging.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324738835&siteId=291194637