怎样用“rownum”在Oracle排序后结果集取指定记录

来源:百度知道 编辑:UC知道 时间:2024/06/01 04:20:50
--按批次取值
select formatted_entry
from
(
select formatted_entry from sample
where
……
order by to_number(product_code),sample_number
)
where rownum = i_Batch_No;
语句大致如此。i_Batch_No为批号参数。如果取第二批。则参数为2
但是这样的语句实现起来并不能满足要求。请问应该怎么写?
那用row_number()分析函数可以做吗?

select formatted_entry from (select row_number()over(order by to_number(product_code),sample_number) rn,a.* from sample a where ...)
where rn=i_Batch_No;

为什么不可以?

rownum <= 10
rownum=1能返回一条
rownum=2或者以上的值,没有返回值
大于也没有

写个例子,你自己参考

select * from (
select column_a ,column_b ,rownum column_c
from tname
order by column_a
)
where column_c between 10 and 20