对sql进行分页处理(Oracle版)
直接代码
/// <summary> /// 对sql进行分页处理 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static string GetPaginationSQL(string sql) { int intPageSize = int.Parse(HttpContext.Current.Request["rows"] == null ? "0" : HttpContext.Current.Request["rows"].ToString()); int intCurrentPage = int.Parse(HttpContext.Current.Request["page"] == null ? "0" : HttpContext.Current.Request["page"].ToString()); string sort = HttpContext.Current.Request["sort"]; string order = HttpContext.Current.Request["order"]; int startRow = (intCurrentPage - 1) * intPageSize + 1; int endRow = startRow - 1 + intPageSize; StringBuilder sb = new StringBuilder(); sb.Append("SELECT * FROM ( "); sb.Append("SELECT A.*, ROWNUM RN FROM ( "); sb.AppendFormat("{0} ", sql); sb.Append(string.IsNullOrEmpty(sort) ? "" : string.Format("order by {0} {1} ", sort, order)); sb.AppendFormat(") A WHERE ROWNUM <={0} ", endRow); sb.AppendFormat(") WHERE RN >={0} ", startRow); return sb.ToString(); }