Fetch first n rows in db2 and rownum in oracle if you want to obtain the first n rows in db2, you only need to add fetch first n rows only, but there is no fetch in oracle, many people on the Internet say that oracle's rownum <= n can be used to replace db2's fetch first n rows only, it is incorrect to obtain the first n rows after order by is required for the result set. According to my experiments, the rownum sequence seems to correspond to rowid, while the rowid sequence is related to the data sequence in the inserted Table (I don't know if the real implementation mechanism of oracle is like this, if you have time to study this oracle book system ). See the following oracle instances: www.2cto.com SQL> select rownum, id, age, name from loaddata; rownum id age name ------- ------ 1 200001 22 AAA 2 200002 22 BBB 3 200003 22 CCC 4 200004 22 DDD 5 200005 22 EEE 6 200006 22 AAASQL> select rownum, id, age, name from loaddata order by name; rownum id age name ------- ------ 1 200001 22 AAA 6 200006 22 AAA 2 200002 22 BBB 3 200003 22 CCC 4 200004 22 DDD 5 2 00005 22. Therefore, if you want to sort the first few rows, you can use the subquery select rownum, id, age, name from (select * from loaddata order by name ); however, I think that we should use the standard SQL function row_number () over () instead of the specific oracle function rownum (). You can write select id, age, name from (select row_number () over (order by name) as row_number, id, age, name from loaddata) where row_number <n; in this case, you do not need to consider whether it is in db2 or oracle.