Oracle paging, Fetch period data, top

Source: Internet
Author: User

Oracle does not have the top number feature of SQL Server. Can only be achieved in the form of a period

Code implementation paging, parameters curpage the current page, pageSize per page row, calculate the starting end page number

int startpage = (curPage-1) * pageSize + 1;
int endpage = Curpage * pageSize;

Such as: The current first page, 10 rows per page get 1,10

Current second page, 10 rows per page get 21,20

....

Oracle SQL notation

Take first to tenth data (index starting at 1), equal to TOP 10

SELECT *
From (select T.*, rownum rn from Sys_table t where rownum <= endpage)
where RN >= StartPage

The results are as follows

SELECT *
From (select T.*, rownum rn from Sys_table t where rownum <= 10)
where RN >= 1

Wrong wording

SELECT *
From (select t.* from Sys_users t where rownum <= 10)
where RowNum >= 1

Oracle paging, Fetch period data, top

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.