你好,游客 登录 注册 搜索
背景:
阅读新闻

不同数据库Oracle MySQL SQL Server DB2 infomix sybase分页查询语句

[日期:2014-09-17] 来源:Linux社区  作者:shefron [字体:大 中 小]

在不同数据库中的使用的分页查询语句:

当前页:currentpage
页大小:pagesize


 1. Oracle数据库

 select * from (select A.*,rownum rn from ( QUERY_SQL ) A )  where rn <= ((currentpage+1)*pagesize) and rn > (currentpage*pagesize)

注:QUERY_SQL为查询sql语句。

或

select * from (select rownum rn,id from TABLENAME  where rownum <=((currentpage+1)*pagesize) ) A  where A.rn >= (currentpage*pagesize)

2. Infomix数据库

select skip currentpage first pagesize * from TABLENAME
 
 3. DB2数据库

 select * from (select 字段1,字段2,字段3,rownumber() over(order by 排序用的列名 asc) as RN from 表名) as A1 where A1.RN between (currentpage*pagesize) and ((currentpage+1)*pagesize) 
  或
 select * from (select rownumber() over(order by id asc ) as rowid from table where rowid <=((currentpage+1)*pagesize) )  where rowid > (currentpage*pagesize)
 
 
 4. SQL Server数据库

 select top pagesize *
  from TABLENAME
  where COLLUMN_NO not in
        (select top currentpage*pagesize COLLUMN_NO from TABLENAME order by COLLUMN_NO)
  order by COLLUMN_NO
 
 5. Sybase数据库

Sybase 12.5.3版本支持top查询,或使用set rowcount N查询头N条数据
 另外采用临时表:
select rowid=identity(12), column_name into #TEMPTABLE from TABLENAME
 select column_name  from #TEMPTABLE where rowid >(currentpage*pagesize) and rowid < (currentpage*pagesize+pagesize)

6. MySQL数据库

 SELECT * FROM TABLE1 LIMIT (currentpage*pagesize),pagesize

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-09/106793.htm

linux
相关资讯       Oracle分页查询语句  分页查询 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款