Oracle uses SQL to make paging statements, methods, easy to use, huh, ...

xiaoxiao2021-03-06  40

After reading a lot of paging articles, I feel that I only use SQL to use simple and straightforward. I will study it simply ... However, the knowledge of the oracle database is really limited. If there is anything wrong, please ask more advice, efficiency, I don't know how to measure, I only take advantage of it ... small experience: Select * from tablename where rownum> 10 and rownum <20 is not right, Oracle thinks that the conditions are not established, so why is so mentally, I don't know ...... ROWNU can only be used by <=, not to use> = SELECT * from Tablename WHERE ROWNUM <20 minus selection * from Tablename WHERE ROWNUM <10 can also achieve the purpose of paging, but does not support the long field, so still use Let's take it ... --------------------------------------------- ----------------------------------------- Method 1, it is said to be efficient as SELECT * From (Select Rownum IDD, T. * from (Select * from gsdtlongtest Order by id desc) Twhere rownum <20) TT where tt.idd> 10

Select * from (select rownum IDD, t. * from (select * from gsdtlongtest order by id desc) twhere rownum StartCurpage Current page PageNum Each page Show Slide START = (CURPAGE-1) * Pagenumend = start PAGENUM 1

Last page If it is insufficient Pagenum doesn't matter ----------------------------------------- ------------------------------------------ Method 2 (43 records, 20, page 2: Select * from (select * from gsdtlongtest where rownum <= 23) Where id NOTSDTLONGTEST WHERE ROWNUM <= 3) Order By ID DESC

Select * from (select * from gsdtlongtest where rownum <= start) Where id not in (Select ID from gsdtlongTest where rownum <= end) Order by ID DESC

START = TOTAL- (CURPAGE-1) * Pagenumend = start-Pagenum 1

Note: In order to reduce the number of subqueys, paging calculations directly according to the default database record order. The primary key ID is increased, and the latest record is the last record in the table. Efficiency doesn't know how ...

-------------------------------------------------- -------------------------------------

转载请注明原文地址:https://www.9cbs.com/read-52208.html

New Post(0)