Mybatis+Oracle: Conditional paging

Code analysis:

SELECT b表.*,ROWNUM  FROM
       (SELECT a.*,ROWNUM rn FROM a table(WHERE condition...multiple)) b
               WHERE b.rn> start index AND b.rn < end index;

Paging principle: (no conditions)
Step 1: What to start with. . . ?
The second part: where to end the value. . . ?
 
 
 
 
 
 Paging principle: (conditional) 
Step 1: Analyze the conditions. . . (Query the conditional data as a new table to implement paging)
Step 2: Where to start taking values. . . ? The third part: where to end the value. . . ?

Example:
Take the employee table as a column: (
query employee information with department number 10, display the first 2 records;
condition: (department number=30), 2 data per page)

Step 1: Query all employee information with department number 30
SELECT a.*,ROWNUM rn FROM emp a WHERE deptno = 30;

Step 2: Add paging on the basis of Step
1. Page 1:
SELECT b.*,ROWNUM FROM
       (SELECT a.*,ROWNUM rn FROM emp a WHERE deptno = 30) b
               WHERE b.rn>0 AND b.rn < 3;
second page
  SELECT b.*,ROWNUM FROM
       (SELECT a.*,ROWNUM rn FROM emp a WHERE deptno = 30) b
               WHERE b. rn>2 AND b.rn < 5;        

 
 



 
 

Guess you like

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