Hi Folks,
You Can ONLY use < or <= when
comparing to ROWNUM
SQL> select empl_nm from hr_public
2 where rownum
between 2 and 10;
no rows selected
;
1 select empl_nm from hr_public
2* where rownum
= 10
SQL> /
no rows selected
;
1 select empl_nm from hr_public
2* where rownum
<10
SQL> /
EMPL_NM
--------------------------------------------------
Graham,David D
DeSantiago,Anthony J
Heinlen,Richard H
Wikelius,Mark R
Hughes,Patrick Coover
Raati,Roberta A
Terry,Andrew W
Pearce,Dennis E
Fallon,Beverly E
9 rows selected.
;
1 select empl_nm from hr_public
2* where rownum
<= 10
SQL> /
EMPL_NM
--------------------------------------------------
Graham,David D
DeSantiago,Anthony J
Heinlen,Richard H
Wikelius,Mark R
Hughes,Patrick Coover
Raati,Roberta A
Terry,Andrew W
Pearce,Dennis E
Fallon,Beverly E
Plutko,Ernest G
10 rows selected.
Also, as a previous post noted, the ROWNUM is assigned as the data is returned ( Pre-Sort ) and in Oracle there is no
way to know, in general, in what order the data is stored.
To get the 10th to 20th row of a sorted list you wil need a subquery:
Select * from (select empl_nm from hr_public order by empl_nm) where rownum < 21
minus
Select * from (select empl_nm from hr_public order by empl_nm) where rownum < 11
EMPL_NM
--------------------------------------------------
Abbe,Giles J
Abbott,Kevin E
Abear,Dale D
Abel,Elizabeth Jean
Abel,Jerome A
Abernathy,Jennifer Lynn
Abfalter,Robert A
Abrahamson,David A
Abrahamson,Duane E
Abu-shaqra,Diaa F.
10 rows selected.
SQL>
-------------------------------------------------
These are NOT, however, the 10th to 20th record as they are stored..That is indeterminate..( Affected by indexes, space available in tablespace, etc)
hth, ROWNUM has led many folks down a false path...
![[profile] [profile] [profile]](/data/assets/smilies/profile.gif)