The rownum field in Oracle is a strange field. Take a test table with 26 records as an example.
Select * from test where rownum> = 1;
Select * from test where rownum> = 2;
Select * from test where rownum <= 10;
26 records were found in the first SQL statement, 10 records were not found in the second SQL statement, and 10 records were found in the third SQL statement.
This is because rownum is a virtual field that is generated gradually when output is recorded.
For the first SQL statement, the rownum of the first record is 1, and the condition is output. Therefore, the rownum of the second record is 2, and the condition is output, all records are retrieved.
For the second SQL statement, the rownum of the first record is 1, which does not meet the condition and is not output. Therefore, the rownum of the second record is still 1. If the condition is not met, it is not output, none of the records were found.
For the third SQL statement, the rownum of the first record is 1, and the condition is output. Therefore, the rownum of the second record is increased to 2, and the condition is output, until the rownum of all the records after 11th and is changed to 11, the condition is not met and is not output.
Therefore, to query the records from the nth to the mth rows in the test table, we should write as follows:
// Filter the formed rownum
Select * from (
// Use a SELECT statement to enclose the SQL to be queried. At this time, rownum has been formed.
Select row _. *, rownum _ from (select * from test) Row _
) Where rownum _ <= m and rownum _> = N;