使用带有 between 关键字的 oracle Rownum
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7317793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using oracle Rownum with between keyword
提问by diagonalbatman
I am planning to use JDBC Pagination with Oracle (Query based technique ) No caching of results . When i tried to use rownum with between Option , it didn't gave me any results
我计划将 JDBC 分页与 Oracle(基于查询的技术)一起使用,不缓存结果。当我尝试在 Option 之间使用 rownum 时,它没有给我任何结果
select * from mytable where rownum between 10 and 20;
select * from mytable 其中 rownum 介于 10 和 20 之间;
But this gave me results .
但这给了我结果。
select * from mytable where rownum < 20;
Please tel me How to solve this ??
select * from mytable where rownum < 20;
请告诉我如何解决这个问题??
回答by diagonalbatman
I have just answered a very similar question, one way of approaching it would be to do this:
我刚刚回答了一个非常相似的问题,解决它的一种方法是这样做:
select *
from
( select rownum rnum, a.*
from (your_query) a
where rownum <= :M )
where rnum >= :N;
Providing a little wrapper for rownum.
为 rownum 提供一个小包装。
I dont think this is wise for large volume implementations however. Although i haven't tested it.
然而,我不认为这对于大容量实现是明智的。虽然我没有测试过。
回答by Tony Andrews
See this questionfor an explanation of why BETWEEN does not work with ROWNUM and Oracle & Pagination, and this onefor how to perform pagination in Oracle queries.
回答by RoshanS
SELECT *
选择 *
FROM (
从 (
SELECT rownum AS rowCount ,ID,UNIT_NAME
FROM MWT_COMPANY_UNIT )
WHERE rowCount BETWEEN requiredRowNumMinYouWant AND requiredRowNumMaxYouWant
WHERE rowCount BETWEEN requiredRowNumMinYouWant AND requiredRowNumMaxYouWant