How to Limit Oracle Query Result



Share this article :

You may use below command to limit the query result. Taking on example for SAP table E070, column E070.

The query will list out the latest 8 rows inserted to the E070 table, specifically on TRKORR column.

select TRKORR from SAPSR3.E070 where rownum <= 8;

TRKORR
------------------------------------------------------------
DEVK900010
DEVK900011
DEVK900012
DEVK900013
DEVK900014
DEVK900015
DEVK900016
DEVK900017

If you want to list the result of the first 8 rows or last 8 rows, you may need to use the ORDER by query. The command will sort the result by ascending or descending order.

#DESCENDING ORDER

SQL> select TRKORR from (select TRKORR from SAPSR3.E070 
order by TRKORR DESC) where rownum <=8; 

TRKORR
------------------------------------------------------------
DEVK900020
DEVK900021
DEVK900022
DEVK900023
DEVK900024
DEVK900025
DEVK900026
DEVK900027

8 rows selected.
#ASCENDING ORDER

SQL> select TRKORR from (select TRKORR from SAPSR3.E070 
order by TRKORR ASC) where rownum <=8;

TRKORR
------------------------------------------------------------
DEVK900001
DEVK900002
DEVK900003
DEVK900004
DEVK900005
DEVK900006
DEVK900007
DEVK900008

8 rows selected.

Related posts

Difference: sqlplus /nolog & /as sysdba
V$ARCHIVED_LOG: Archived Log Information from Control File
ORA-28000: the account is locked
Steps to Patch Oracle 10.2.0.1.0 to 10.2.0.4.0
© 2017 ITsiti. All Rights Reserved
Powered by KEEM