Oracle分页查询语句

------------------------------------------------
select
B.*
from
(
select
    A.*,
    rownum as newRowNum
from
(
    select t.*,rownum from TABLE_NAME t
) A
where
    rownum<10
) B
where B.newRowNum>5
------------------------------------------------
select A.*
from
(
select t.*, rownum as newRowNum
from TABLE_NAME t
where rownum<10
) A
where newRowNum>5
------------------------------------------------
select
B.*
from
(
select
    A.*,
    rownum as newRowNum
from
(
    select t.*,rownum from gzhw_saved_rpt t
) A
) B
where B.newRowNum>5 and B.newRowNum<10
------------------------------------------------
SELECT * FROM
(
SELECT A.*, ROWNUM newRowNum
FROM (SELECT * FROM TABLE_NAME) A
)
WHERE newRowNum BETWEEN 5 AND 10
------------------------------------------------



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

select *
from
(
    select rid
    from
    (
        select rownum rn, rid
        from (select rowid rid from lg_order o order by o.order_id)
        where rownum <= 20
    )
    where rn >= 10) t1, lg_order t2
where t2.rowid = t1.rid


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

你可能感兴趣的:(oracle)