Paging Paging Oracle and MySQL difference between the conversion

A, Mysql use limit pagination

select * from stu limit m, n; //m = (startPage-1)*pageSize,n = pageSize

The PS:
(. 1) the first parameter represents the starting value of m + 1 line, the second parameter indicates how many rows take (page size)
(2) m = (2-1) * + 10. 1, = n-10, represents a limit 11,10 Starting line 11, line 10 take, i.e., the second page data. SELECT * FROM table LIMIT 5,10; // retrieve rows 6-15
(. 3) m, n-parameter values can not be written in the statement which evaluates the expression, must calculate the value written before the statement.

Two, Oracle rownum use pagination

select * from (
select rownum rn,a.* from table_name a where rownum <= x //结束行,x = startPage*pageSize
)
where rn >= y; //起始行,y = (startPage-1)*pageSize+1

The PS:
(. 1)> = y, <y = X represents a row from the first (starting line) ~ x row (row end)
(2) Comparative rownum only less than, greater than comparison can not, because the query is the first ordered rownum , for example, your condition rownum> 1, when the query to the first data, rownum 1, no conditions are met. 2, 3 ... Similarly, it has not meet the conditions, so they did not return a result. So when queries need to set up an alias, and then judge by calling the alias greater than after the inquiry is completed.

Three, MySQL and Oracle conversion

Known m, n seeking X, Y
X = (m / n-+ 1'd) * n-
Y = m +. 1

Released eight original articles · won praise 0 · Views 42

Guess you like

Origin blog.csdn.net/weixin_44226956/article/details/105161299