Implement select Top N in Oracle:
Since Oracle does not support the select top statement, order by and rownum are often used in Oracle.
To query the 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 Records extracted)
Order by rownum ASC
For example, select ID, name from (select ID, name from student order by name) Where rownum <= 10 order by rownum ASC
Sort the top 10 pieces of data by name
Appendix: Method for retrieving-data records
1. Best Choice:Using analysis functions
Row_number () over (partition by col1 order by col2)
For exampleRetrieve-records, sorted by tname
Select tname, tabtype from (
Select tname, tabtype, row_number () over (order by tname) Rn from Tab
) Where rn between 100 and 150;
2. Use rownum as the virtual Column
Select tname, tabtype from (
Select tname, tabtype, rownum rn from TabWhere rownum <= 150
) Where rn >=100;