Rownum伪例使用的限制:
SQL>; select rownum,month,sell from sale where rownum=1;(可以用在限制返回记录条数的地方,保证不出错,如:隐式游标)
SQL>; select rownum,month,sell from sale where rownum=2;(1以上都查不到记录)
SQL>; select rownum,month,sell from sale where rownum>;5;
(由于rownum是一个总是从1开始的伪列,Oracle 认为这种条件不成立,查不到记录)
所以,使用Rownum限制只能rownum<n的方式
那么如何获得比如5到10行的结果呢?有两种办法:
1、用minus
select rownum,month,sell from sale where rownum<10
minus
select rownum,month,sell from sale where rownum<5;
2、利用子查询,在子查询中通过rownum新创造一个列,然后根据这个列进行限制
Select * From
(Select Rownum row_id,a.*
From boss_user a
Where Rownum<20)
Where Row_id Between 5 And 10;
其中第二行a.*是必须的,不能直接用*来查询