ORACLE paging solution under large data volume: http://ddkangfu.blog.51cto.com/311989/ 1425797/
oracle paging data duplicate data is incorrect: https://my.oschina.net/u/852445/blog/402325
Example:
SELECT * FROM ( SELECT RS.AMOUNT,RS.AREA,RS.AREANAME,[color=red]ROWNUM rn FROM ( SELECT ( CASE WHEN oy.AMOUNT IS NULL THEN ny.AMOUNT-0 WHEN ny.AMOUNT IS NULL THEN 0-oy.AMOUNT ELSE ny.AMOUNT-oy.AMOUNT END) AS amount,NY.AREA,NY.areaName FROM (SELECT "SUM"(VI.AMOUNT) AS AMOUNT ,VI.AREA, dm.AREA_NAME as areaName FROM VI_INCOME_ITEM_MAPPING VI LEFT JOIN DM_AREA dm ON VI.AREA = dm.AREA_CODE WHERE VI.T_ITEM = #{BudgetTItem,jdbcType=VARCHAR} AND VI.BLEVEL ='3' AND "SUBSTR"(VI.TXN_DATE,1,6) <![CDATA[ >= ]]> #{startMonth,jdbcType=VARCHAR} AND "SUBSTR"(VI.TXN_DATE,1,6) <![CDATA[ <= ]]> #{endMonth,jdbcType=VARCHAR} GROUP BY VI.AREA,dm.AREA_NAME) ny LEFT JOIN (SELECT "SUM"(VI.AMOUNT) AS AMOUNT ,VI.AREA, dm.AREA_NAME as areaName FROM VI_INCOME_ITEM_MAPPING VI LEFT JOIN DM_AREA dm ON VI.AREA = dm.AREA_CODE WHERE VI.T_ITEM = #{BudgetTItem,jdbcType=VARCHAR} AND VI.BLEVEL ='3' AND "SUBSTR"(VI.TXN_DATE,1,6) <![CDATA[ >= ]]> #{lastStartMonth,jdbcType=VARCHAR} AND "SUBSTR"(VI.TXN_DATE,1,6) <![CDATA[ <= ]]> #{lastEndMonth,jdbcType=VARCHAR} GROUP BY VI.AREA,dm.AREA_NAME) oy ON NY.AREA = OY.AREA ORDER BY amount DESC ) [color=red]rs WHERE ROWNUM <= 10) WHERE rn >0
Note that ROWNUM is used for the inner layer of the red font, and RN is used for the outer layer. Generally, when Oracle selects for the first time, there is ROWNUM, which can be used for paging in the second layer. There are two methods for
paging :
the first one:
SELECT * FROM (SELECT t.*,ROWNUM as rowno FROM (SELECT * FROM test ORDER BY ADD_TIME ) t ) WHERE rowno BETWEEN 200001 AND 300000;
The second:
SELECT * FROM ( SELECT t.*,ROWNUM as rowno FROM (SELECT * FROM test ORDER BY ADD_TIME) t WHERE ROWNUM <= 300000) WHERE rowno >=200001
The second is more effective than the first, because the second locks the paging result set, while the first is to paginate from all the records in the table;
for two-level nested paging queries such as:
Example:
select (select * from test ORDER BY ADD_TIME) where ROWNUM between 100000 and 200000
For ORDER BY ADD_TIME, the order field ADD_TIME field must be a unique index, otherwise the
result set is empty, or the data is duplicated.