/// <summary>
/// 返回分页SQL语句
/// </summary>
/// <param name="selectSql">查询SQL语句</param>
/// <param name="PageIndex">当前页码</param>
/// <param name="PageSize">一页多少条记录</param>
/// <returns></returns>
public static string getPageSplitSQL(string selectSql, int PageIndex, int PageSize)
{
string StartSelectSql = @" select * from (select aa.*, rownum r from (";
int CurrentReadRows = PageIndex * PageSize;
int startRow = (CurrentReadRows - PageSize) < 0 ? 0 : (CurrentReadRows - PageSize);
int endRow = CurrentReadRows == 0 ? PageSize : CurrentReadRows;
string EndSelectSql = string.Format(") aa where rownum <= {1}) bb where r >{0} ", startRow, endRow);
return StartSelectSql + selectSql + EndSelectSql;
}
获取分页的查询语句-针对MS2005和Oracle
分页SQL生成方法
最新推荐文章于 2025-12-03 12:12:23 发布
本文介绍了一种通过输入查询SQL语句、当前页码及每页记录数来生成分页SQL的方法。该方法适用于Oracle数据库,通过计算起始读取行数和结束读取行数,构造出包含ROWNUM伪列的复杂SQL语句实现分页功能。
4098

被折叠的 条评论
为什么被折叠?



