说说oracle分页的sql语句
说说oracle分页的sql语句,分排序和不排序两种。
当结果集不需要进行排序时,每页显示条数为:rowPerPage,当前页数为:currentPage。
1、 相对来说,这种查询速度会快一些,因为当currentPage小时,嵌套语句查询的结果集小。但当currentPage 变大时,查询速度会慢慢变慢。当结果集很大时,查询第一页跟最后一页的速度会有明显变化。(倾向用这种!)
select * from(
select rownum r, field1,field2 from table_name where rownum <= currentPage * rowPerPage
)
where r > (currentPage-1) * rowPerPage
2、相对来说,这种查询速度会慢一些,无论当currentPage大小,嵌套语句查询的结果集都是一样多的,都是整个结果集。但是,当结果集很大时,查询第一页跟最后一页的速度不会有明显变化。
select * from(
select rownum r, field1,field2 from table_name
)
where r > (currentPage-1) * rowPerPage and r <= currentPage * rowPerPage
当需要进行排序时,以第一种方式进行示例如下:
select * from(
select rownum r, a.* from (
select field1,field2 from table_name order by field1
) a where rownum <= currentPage * rowPerPage
) where r > (currentPage-1) * rowPerPage
还有这个,也是很好用的:
select * from (select a.*,rownum row_num from (select * from tabelTest t order by t.id ) a ) b where b.row_num between (currentPage-1)*pagesize and currentPage*pagesize//
public string List(int page, int rows, string sort, string order, string DataBase)
{
string where = Common.HqlQeuryHelp.GetWhere(typeof(Model.TIPTOP.CPF_FILE), "CPF01,CPF02,CPF29,CPF31,CPF70,CPF35");
//string OracelStr = "select cpf01,cpf02,cpf29,cpf31,cpk02,cqi02,cqi06,cqi09,cqi06-cqi09 as diff,cpf70,cpf35,rownum as rowi from ";
// OracelStr += "tekvertps.cqi_file,tekvertps.cpf_file it,tekvertps.cpk_file where cpf31=cpk01 and cpf01=cqi01 and cpf35 is null and rownum<100"; string OracelStr = "select cpf01,cpf02,cpf29,cpf31,cpk02,cqi02,cqi06,cqi09,cqi06-cqi09 as diff,cpf70,cpf35,rownum as r from ";
OracelStr += "(select cpf01,cpf02,cpf29,cpf31,cpk02,cqi02,cqi06,cqi09,cqi06-cqi09 as diff,cpf70,cpf35,rownum row_num from ";
OracelStr += "tekvertps.cpf_file, tekvertps.cqi_file,tekvertps.cpk_file where cpf31=cpk01 and cpf01=cqi01 and cpf35 is null order by cpf01 ) it ";
OracelStr += "where it.row_num between " + (page-1)*rows +" and " + page*rows; if (!string.IsNullOrEmpty(where)) { OracelStr += " and " + where; }
OracleDataReader dr = OA.Common.OracleHelper.ExecuteReader(OA.Common.OracleHelper.ConnectionStringTipTopTPS, CommandType.Text, OracelStr, null);
var cpfbll = new BLL.TIPTOP.CPF_FILE(DataBase);
var count = cpfbll.GetTextCount(where); List<object> listView = new List<object>();
foreach (var i in dr)
{
listView.Add(new
{
CPF01 = dr["CPF01"].ToString(),
CPF02 = dr["CPF02"].ToString(),
CPF29 = dr["CPF29"].ToString(),
CPF31 = dr["CPF31"].ToString(),
CPK02 = dr["CPK02"].ToString(),
CQI02 = dr["CQI02"].ToString(),
CQI06 = dr["CQI06"].ToString(),
CQI09 = dr["CQI09"].ToString(),
DIFF = dr["DIFF"].ToString(),
CPF70 = Formate_Date((DateTime)dr["CPF70"]),
CPF35 = dr["CPF35"].ToString()
});
}
var ret = new
{
total = count,
rows = listView
};
return ToJsonString(ret);
}
前台(MVC easyui-datagrid):
<div region="center" border="false">
<table class="easyui-datagrid" id="details" data-options="fit:true,singleSelect:true, fitColumns:true,pageSize:10,
pagination:true,rownumbers:true,border:true,url:serverUrl.list,view: detailview,detailFormatter:detailformatter,onExpandRow:rowExpand">
<thead>
<tr>
<th data-options="field:'CPF01',sortable:true,width:100">員工代號</th>
<th data-options="field:'CPF02',sortable:true,width:100">姓名</th>
<th data-options="field:'CPF29',sortable:true,width:100">部門別</th>
<th data-options="field:'CPF31',sortable:true,width:100">職稱代號</th>
<th data-options="field:'CPK02',sortable:true,width:100">職稱</th>
<th data-options="field:'CQI02',sortable:true,width:100">年度</th>
<th data-options="field:'CQI06',sortable:true,width:100">特休天數</th>
<th data-options="field:'CQI09',sortable:true,width:100">已休天數</th>
<th data-options="field:'DIFF',sortable:true,width:100">未休天數</th>
<th data-options="field:'CQH071S1',sortable:true,width:100">事假天數</th>
<th data-options="field:'CQH071S2',sortable:true,width:100">病假天數</th>
<th data-options="field:'CPF70',sortable:true,width:100">到職日期</th>
<th data-options="field:'CPF35',sortable:true,width:100">離職日期</th>
</tr>
</thead>
</table>
</div>
说说oracle分页的sql语句的更多相关文章
- oracle 分页的sql语句
已知有两种方法效率上貌似第一种更优: 1. select * from( select t1.*, rownum n from (select * from cm_log order by oper_ ...
- Oracle分页查询sql语句
1. select * from ( select t.*, rownum RN from TABLE_NAME t ) where RN > 0 and RN <= 15 2. se ...
- Oracle数据库 基础SQL语句练习
一.说明 第一次使用Oracle,想做一些练习,熟悉一些oracle. 表:使用的是scott用户,默认的表 具体表讲解,可以参考该文档:https://www.cnblogs.com/xjcheng ...
- oracle中查看sql语句的执行计划
1.在pl/sql中打开cmd命令容器 2.在cmd命令窗口中输入:explain plan for select * from t; 3.查看sql语句的执行计划:select * from tab ...
- Oracle 的分页查询 SQL 语句
Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. 分页查询格式: SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM T ...
- ORACLE分页查询SQL语法——最高效的分页
--1:无ORDER BY排序的写法.(效率最高)--(经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!) SELECT * FROM (SELECT ...
- ORACLE分页查询SQL语法——高效的分页
--1:无ORDER BY排序的写法.(效率最高)--(经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!) SELECT * FROM (SELECT ...
- 160321、ORACLE分页查询SQL语法——最高效的分页
--1:无ORDER BY排序的写法.(效率最高) --(经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!) SELECT * FROM (SELE ...
- Oracle数据库的sql语句性能优化
在应用系统开发初期,由于开发数据库数据比较少,对于查询sql语句,复杂试图的编写等体会不出sql语句各种写法的性能优劣,但是如果将应用系统提交实际应用后,随着数据库中数据的增加,系统的响应速度就成为目 ...
随机推荐
- WordPress显示备案号
备案时,需要显示备案号,而wordpress默认模板本身不带这个信息,为了更快速应付备案,解决方案如下: 根据wp-config.php的提示 .......... /** * zh_CN本地化设置: ...
- Maven实战(一)安装与配置
1. 简介 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 如果你已经有十次输入同样的Ant targets来编译你的代码.jar或者w ...
- json的eval为什么要用msg.d
在做一个关于搜索功能时用到了jquery autocomplete,发现返回数据时都用到了一个.d,比如: var datas = eval('(' + msg.d + ')'); 这个.d是什么呢, ...
- Xor Sum---hdu4825(01字典树模板)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...
- TestNG学习-001-基础理论知识
此 文主要讲述用 TestNG 的基础理论知识,TestNG 的特定,编写测试过程三步骤,与 JUnit4+ 的差异,以此使亲对 TestNG 测试框架能够有一个简单的认知. 希望能对初学 TestN ...
- [转]详细介绍java中的数据结构
详细介绍java中的数据结构 本文介绍的是java中的数据结构,本文试图通过简单的描述,向读者阐述各个类的作用以及如何正确使用这些类.一起来看本文吧! 也许你已经熟练使用了java.util包里面的各 ...
- JQuery:JQuery设置HTML
JQuery:设置HTML1.Query - 设置内容和属性设置内容 - text().html() 以及 val()我们将使用前一章中的三个相同的方法来设置内容: text() - 设置或返回所选元 ...
- dd命令使用详解
dd命令使用详解 http://www.cnblogs.com/qq78292959/archive/2012/02/23/2364760.html 1.命令简介 dd 的主要选项: 指定数字的地方若 ...
- Sersync实现触发式文件同步 替代inotify和rsync
Sersync实现触发式文件同步 替代inotify和rsync Pyinotify是一个Python模块,用来监测文件系统的变化. Pyinotify依赖于Linux内核的功能—inotify(内核 ...
- Vue.2.0.5-过渡效果
概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.c ...