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