我有一个过程,在某些条件和特定顺序上返回多行。这些行分为几页(每页50行)。 如何从具有特定行的页面检索所有行。 我创建了一个查询执行此工作的查询,但它没有进行优化,并且对性能产生巨大影响。请帮助我优化它或替代它:
select *
from
(
select file_id, row_number() over (order by rownum) rn
from my_table
)
where trunc(rn/50) = (
select trunc(rn/50) from
(select t.*, rownum rn from my_table t)
where file_id = 29987);
答案 0 :(得分:0)
你必须调整一下......
with tab as
(
-- the
-- row_number() over (order by rownum) rn
-- should be here
select level + 1000 as val
, level/50 as rn_50
from dual
connect by
level < 140
)
, val as
(
select rn_50
from tab
where val = 1004 -- pg 1
--where val = 1051 -- pg 2
--where val = 1101 -- pg 3
)
select *
from tab t
where rn_50 >= (select floor(rn_50) from val)
and rn_50 <= (select ceil (rn_50) from val)
;