对于Oracle数据库,可以直接采用SQL语句的形式,查询出每页的记录
方案一:
/// <summary>
/// 生成分页SQL
/// </summary>
/// <param name="_sqlStr">查询的SQL,支持多表关联,排序等</param>
/// <param name="_sortStr"></param>
/// <param name="_startNum">开始行</param>
/// <param name="_pageSize">记录数</param>
/// <returns></returns>
private string BuildPagerSQL(string _sqlStr, int _startNum, int _pageSize)
{
string sqlStr = _sqlStr;
_sqlStr = _sqlStr.Insert(7, " ROWNUM R , ");
sqlStr = "SELECT * FROM ( ";
sqlStr += _sqlStr + " ) T1 , ( ";
sqlStr += " SELECT R FROM ( SELECT R , ROWNUM C FROM ( ";
sqlStr += _sqlStr + " ) ) WHERE C > " + _startNum
+ " AND C <= " + (_startNum + _pageSize) + " ) T2 WHERE T1.R = T2.R";
return sqlStr;
}
方案二:
private string BuildPagerSQL(string sqlStr , int StartNum , int PageSize)
{
int endNum = StartNum + PageSize;
string _sqlStr = @"select B.* from ( select A.* , RowNum rn from
( " + sqlStr + " ) A where RowNum < '" + endNum + "' ) B where rn > '" + StartNum + "'";
return _sqlStr;
}
方案一:
/// <summary>
/// 生成分页SQL
/// </summary>
/// <param name="_sqlStr">查询的SQL,支持多表关联,排序等</param>
/// <param name="_sortStr"></param>
/// <param name="_startNum">开始行</param>
/// <param name="_pageSize">记录数</param>
/// <returns></returns>
private string BuildPagerSQL(string _sqlStr, int _startNum, int _pageSize)
{
string sqlStr = _sqlStr;
_sqlStr = _sqlStr.Insert(7, " ROWNUM R , ");
sqlStr = "SELECT * FROM ( ";
sqlStr += _sqlStr + " ) T1 , ( ";
sqlStr += " SELECT R FROM ( SELECT R , ROWNUM C FROM ( ";
sqlStr += _sqlStr + " ) ) WHERE C > " + _startNum
+ " AND C <= " + (_startNum + _pageSize) + " ) T2 WHERE T1.R = T2.R";
return sqlStr;
}
方案二:
private string BuildPagerSQL(string sqlStr , int StartNum , int PageSize)
{
int endNum = StartNum + PageSize;
string _sqlStr = @"select B.* from ( select A.* , RowNum rn from
( " + sqlStr + " ) A where RowNum < '" + endNum + "' ) B where rn > '" + StartNum + "'";
return _sqlStr;
}