rownum真让人苦恼

cnliutian 2004-11-24 11:09:48
最近要做JSP分页的问题
中间涉及到从数据库一个表中取第10-20条的数据
这样我就想到了使用rownum
我在SQLPLUS中输入select * from tab where rownum < 10;这条是可以执行的,并且有结果集被返回。
但当我输入select * from tab where rownum between 5 and 10;却不能返回结果集,而tab表的结果集绝对是大于10条数据的
然后我又试了select * from tab where rownum > 5 and rownum < 10;也是不能有结果集被返回。
我现在不知道是我的SQL语句构造有问题还是oracle数据库不支持rownum区间查询?

请高手帮忙解答
...全文
186 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shine333 2004-11-25
  • 打赏
  • 举报
回复
对,没错。rownum只能用<=

oracle888 2004-11-25
  • 打赏
  • 举报
回复
你可以放到缓存(数组),然后控制就方便了。
GerryYang 2004-11-25
  • 打赏
  • 举报
回复
rownum不能用<
如果要取5到10的记录,可以:
select * from (select tab.*,rownum rn from tab where rownum<=10) where rn>=5
phant0m 2004-11-25
  • 打赏
  • 举报
回复
rownum>= 不能这么写,只能是rownum<
baojianjun 2004-11-25
  • 打赏
  • 举报
回复
select * from tab where rownum between 5 and 10

改為:
select * from tab where rownum <= 10
minus
select * from tab where rownum <= 5
zjd5688 2004-11-25
  • 打赏
  • 举报
回复

select * from (select tab.*,rownum rn from tab) where rn>=5 and rn<=10
cnliutian 2004-11-25
  • 打赏
  • 举报
回复
to:oracle888()
什么叫缓存(数组)?

17,380

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧