Oraclerownum Case Study

Source: Internet
Author: User
Select a row of records in the Table: (understanding: rownum is the number of rows sequentially allocated from the query in oracle) select * from (selectrownuma, t. * fromte

Select a row of records in the Table: (understanding: rownum is the number of rows sequentially allocated from the query in oracle) select * from (select rownum a, t. * from te

Select a row of records in the Table: (understanding: rownum is the number of rows sequentially allocated from the query returned by the Oracle System)
Select * from (select rownum a, t. * from testtab t) where a = 2;
Select * from (select rownum a, t. * from testtab t) where a = 3;
Select * from (select rownum a, t. * from testtab t) where a = 4;
Cannot be:
Select * from (select rownum, t. * from testtab t) where rownum = 2; or
Select * from testtab where rownum = 2;
Multiple rows of records are returned:
Select * from testtab where rownum <= 10;
Return a record segment: (for example, 4-10 rows in the record table)
Select * from (select rownum no, testtab. * from testtab where rownum <= 10) where no> = 4;
Return a qualified and sorted segment of records:
Select rownum num1, tt. * from
(Select rownum num, t. * from
(Select EcodeInfo. * from EcodeInfo where a = 1 order by ecode desc) t) tt
Where num> 19 and rownum <20>
It is assumed that oracle extracts records before sorting, while oracle's rownum is generated after extracting records, which is prior to sorting. Therefore, you must use subqueries to sort records first.
Cannot be:
Select * from tsettab where rownum> 10;
Return the last record:
Select * from (select rownum a, t. * from testtab t) where a = (select count (*) from testtab );
Returns the last N rows of records:
Select * from (select rownum a, t. * from testtab t) where a = (select count (*)-N from testtab );

----------------
Select * from adminrole where rownum <= 4
Minus
Select * from adminrole where rownum <2>

Select * from
(Select rownum row_id, B. * from (select a. * from sorttable a order by sortid) B)
Where row_id between 5 and 9;

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.