说说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
后台,cs将json传入前台easy-ui的datagrid:
//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
前台(MVC easyui-datagrid):
員工代號 姓名 部門別 職稱代號 職稱 年度 特休天數 已休天數 未休天數 事假天數 病假天數 到職日期 離職日期