Oracle分页SQL


 错误写法:

select a.*, rownum r
from (select * from lg_order o order by o.order_id) a
where rownum <= 20
and rownum >= 10

正确写法:

select *
from (select a.*, rownum r
from (select * from lg_order o order by o.order_id) a
where rownum <= 20) b
where r >= 10

第一句是错误的 由于rownum是一个总是从1开始的伪列,Oracle 认为这种条件不成立,查不到记录
执行顺序从内到外,从右到左

posted on 2011-04-13 20:22  IceWee  阅读(441)  评论(0编辑  收藏  举报

导航