Oracle, SQL Server, Access database high effect paging tips

Source: Internet
Author: User
Tags table name access database oracle database

1. SQL Server, Access database

This is all Microsoft's database, is a family, the basic operation is similar, often using the following paging statement:

PAGESIZE: Number of records displayed per page

CurrentPage: Current page number

The name of the datasheet is: components

Index PRIMARY key word is: ID

以下是引用片段:
select top PAGESIZE * from components where id not in
(select top (PAGESIZE*(CURRENTPAGE-1))
id from components order by id)order by id

such as the following:

以下是引用片段:
select top 10 * from components where id not in
(select top 10*10 id from components order by id)
order by id

Select from 101 Records, select only the previous 10 records

2. Oracle Database

Since the Oracle database does not have the top keyword, there are two ways to do this, as Microsoft's data does:

(1), one is to use the contrary.

PAGESIZE: Number of records displayed per page

CurrentPage: Current page number

The name of the datasheet is: components

Index PRIMARY key word is: ID

以下是引用片段:
select * from components where id not
in(select id from components where
rownum<=(PAGESIZE*(CURRENTPAGE-1)))
and rownum<=PAGESIZE order by id;

The following example:

以下是引用片段:
select * from components where id not in
(select id from components where rownum<=100)
and rownum<=10 order by id;

Select from 101 to record and select the first 10.

(2), the use of minus, that is, the Chinese meaning is minus.

以下是引用片段:
select * from components where rownum
<=(PAGESIZE*(CURRENTPAGE-1)) minus
select * from components where rownum
<=(PAGESIZE*(CURRENTPAGE-2));

As an example: SELECT * from Components where

以下是引用片段:
rownum<=10 minus select * from components
where rownum<=5;.

(3), one is the use of Oracle's rownum, this is an Oracle query automatically return the sequence number, generally not shown, but can be seen through the select RowNum from [table name], note that it is from 1 to the current total number of records.

以下是引用片段:
select * from (select rownum tid,components.
* from components where rownum<=100) where tid<=10;

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.