加个入库时间reg_time,依据reg_time正序排列,选择最后n条。select content,reg_time from select content,reg_time,rownum row_id from (select content,reg_time from :tab1 order by reg_time) a, (select count(*) row_max from tab1) b where row_id between b.row_max-:n and b.rowmax 或按入库时间倒序排列取最前面n条,再倒序比较一下速度。加了倒序的要稍微慢一点。 还有最快的当然是耕具ROWID来查询。
from
select content,reg_time,rownum row_id
from
(select content,reg_time from :tab1 order by reg_time) a,
(select count(*) row_max from tab1) b
where row_id between b.row_max-:n and b.rowmax
或按入库时间倒序排列取最前面n条,再倒序比较一下速度。加了倒序的要稍微慢一点。
还有最快的当然是耕具ROWID来查询。
你可以考虑在入库单号+入库时间上建立索引