MyBatis Oracle Paging SQL

Source: Internet
Author: User

The SQL used to write Oracle paging was:

(1)

SELECT *
From (select A.*, RowNum rnum
From (select ID, data
From T order by ID, ROWID) a
)
where Rnum >= 148 and rnum<=151;


Or

(2)
SELECT *
From (select A.*, RowNum rnum
From (select ID, data
From T order by ID, ROWID) a
where rownum <= 151)
where Rnum >= 148;

Recently in the development of colleagues said that the efficiency of the first (1) is not good, and the first (2) in a unique value (column) of the time to normal order, has been used in paragraph (1), today, colleagues find the following way to solve the first (2) Unique values (column) sorting problem, as follows:

(3)

SELECT *
From (select A.*, RowNum rnum
From (select ID, data
From T order by ID, rowid) A
where rownum <= 151)
where Rnum >= 148;

PS: The main is to add the rowid this field.

Reference website: http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html

MyBatis Oracle Paging SQL

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.