SELECTs using the ORDER BY clause with rownum : rownum « Query Select « Oracle PL/SQL Tutorial






SQL>
SQL> SELECT username, default_tablespace FROM dba_users where rownum < 50;

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
JAVA2S                         SYSTEM
SYS                            SYSTEM
SYSTEM                         SYSTEM
ANONYMOUS                      SYSAUX
PLSQL                          USERS
MDSYS                          SYSTEM
OUTLN                          SYSTEM
DIP                            SYSTEM
TSMSYS                         SYSTEM
FLOWS_FILES                    SYSAUX
CTXSYS                         SYSAUX
DBSNMP                         SYSAUX
FLOWS_020100                   SYSAUX
XDB                            SYSAUX
HR                             USERS

15 rows selected.

SQL>
SQL> SELECT username, default_tablespace
  2  FROM dba_users
  3  where rownum < 50
  4  ORDER BY username;

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
ANONYMOUS                      SYSAUX
CTXSYS                         SYSAUX
DBSNMP                         SYSAUX
DIP                            SYSTEM
FLOWS_020100                   SYSAUX
FLOWS_FILES                    SYSAUX
HR                             USERS
JAVA2S                         SYSTEM
MDSYS                          SYSTEM
OUTLN                          SYSTEM
PLSQL                          USERS
SYS                            SYSTEM
SYSTEM                         SYSTEM
TSMSYS                         SYSTEM
XDB                            SYSAUX

15 rows selected.

SQL>








2.31.rownum
2.31.1.Select with rownum
2.31.2.Use rownum to limit the resultset
2.31.3.SELECTs using the ORDER BY clause with rownum
2.31.4.Getting the Five Most Expensive Products