Oracle paging query example

Oracle pagination query example:

SELECT * FROM ( SELECT A.*, ROWNUM RN 
FROM (SELECT * FROM TABLE_NAME) A WHERE ROWNUM <= 40 ) WHERE RN >= 21

It means to query lines 21 to 40

The innermost query SELECT * FROM TABLE_NAME represents the original query statement without page turning. ROWNUM = 21 controls the range per page for paginated queries.

The paging query statement given above has higher efficiency in most cases. The purpose of paging is to control the size of the output result set and return the results as soon as possible. In the above paging query statement, this consideration
is mainly reflected in WHERE ROWNUM

There are two ways to select the 21st to 40th records. One is to control the maximum value through ROWNUM<= 40 in the second layer of the query shown in the above example, and control the minimum value in the outermost layer of the query. Another way is to remove the WHERE ROWNUM<=40 statement in the second layer of the query, and control the minimum and maximum values ​​of paging at the outermost layer of the query.

I have never used Oracle, I copied it, record it
Please add a picture description

Guess you like

Origin blog.csdn.net/weixin_52799373/article/details/126544506