How Oracle queries the first few data

Source: Internet
Author: User

Implementing select Top N in Oracle:
Because Oracle does not support the SELECT top statement, it is often used in Oracle with order by and RowNum
To implement the query for select top N.
To put it simply, the implementation method is as follows:
Select Column Name 1 ... Column name n from
(
Select Column Name 1 ... Column name N
From table name order BY column name 1
)
where RowNum <=n (number of extracted records)
ORDER BY rownum ASC

such as: Select Id,name from (select Id,name from Student order by name) where rownum<=10 ORDER by rownum ASC

Sort by name remove Top 10 data

Attached: Method of fetching 100-150 data

1. Best choice: Use analytic functions

Row_number () over (partition by col1 ORDER by col2)

For example , to remove 100-150 records, sort by tname.
Select Tname,tabtype from (

Select Tname,tabtype,row_number () over (order by Tname) RN from tab

) where RN between and 150;

2. Using rownum virtual columns

Select Tname,tabtype from (

Select Tname,tabtype,rownum rn from tab where RowNum <=

) where RN >= 100;

How Oracle queries the first few data

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.