存储过程的分页

CREATE PROCEDURE pageTest --用于翻页的测试

--需要把排序字段放在第一列

(

@FirstID nvarchar(20)=null, --当前页面里的第一条记录的排序字段的值

@LastID nvarchar(20)=null, --当前页面里的最后一条记录的排序字段的值

@isNext bit=null, --true 1 :下一页;false 0:上一页

@allCount int output, --返回总记录数

@pageSize int output, --返回一页的记录数

@CurPage int --页号(第几页)0:第一页;-1最后一页。

)

AS

if @CurPage=0--表示第一页

begin

--统计总记录数

select @allCount=count(ProductId) from Product_test

set @pageSize=10

--返回第一页的数据

select top 10

ProductId,

ProductName,

Introduction

from Product_test order by ProductId

end

else if @CurPage=-1--表示最后一页

select * from

(select top 10 ProductId,

ProductName,

Introduction

from Product_test order by ProductId desc ) as aa

order by ProductId

else

begin

if @isNext=1

--翻到下一页

select top 10 ProductId,

ProductName,

Introduction

from Product_test where ProductId > @LastID order by ProductId

else

--翻到上一页

select * from

(select top 10 ProductId,

ProductName,

Introduction

from Product_test where ProductId < @FirstID order by ProductId desc) as bb order by ProductId

end

时间: 2024-07-29 16:57:44

存储过程的分页的相关文章

调用存储过程进行分页实例

我在这使用SQL server数据库和我已有的数据库中的表.表名: HKSJ_Main 1.创建存储过程 --该分页的原理 越过多少条,去多少条 create proc P_page --声明参数@size int , --一页取几条@pageindex int,--取第几页@total int out --返回总条数as beginselect top(@size)* from dbo.HKSJ_Main as B where B.ID not in ( select top((@pagein

java连接oracle数据库调用存储过程实现分页查询(emp为例)

第一步:建一个含游标类型的包 sql>create or replace package testPackage as type test_cursor is ref cursor;    --定义名为test_cursor 的游标 end testPackage; 第二步:编写分页的存储过程 sql>create or replace procedure fenYe( tableName in varchar2,--表名 pageSize in number,--每页显示的记录数 pageN

基于Jquery+Ajax+Json+存储过程 高效分页

1 CREATE PROCEDURE [dbo].[PAGINATION] 2 @FEILDS VARCHAR(1000),--要显示的字段 3 @PAGE_INDEX INT,--当前页码 4 @PAGE_SIZE INT,--页面大小 5 @ORDERTYPE BIT,--当为0时 则为 desc 当为1 时 asc 6 @ANDWHERE VARCHAR(1000)='',--where语句 不用加where 7 @ORDERFEILD VARCHAR(100), --排序的字段 8 @T

MyBatis之四:调用存储过程含分页、输入输出参数

在前面分别讲解了通过mybatis执行简单的增删改,多表联合查询,那么自然不能缺少存储过程调用,而且还带分页功能. 注意:表结构参见上篇讲解联合查询的表. 一.查询某班级以及该班级下面所有学生的记录 上面这个查询可以用sql语句表示为: select c.class_id,c.class_name,s.s_id,s.s_name from Class c left join ClassStudent cs on c.class_id = cs.class_id left join Student

c#+oracle存储过程实现分页

1.在oracle的sqlplus或其他工具中运行一下pl/sql块建立存储过程 --------------------------------------------------------------分页存储过程--------------------------------------------------------------创建包create or replace package testpackage astype test_cursor is ref cursor;end t

封装EF code first用存储过程的分页方法

一年半没有做过MVC的项目了,还是很怀念(因为现在项目还是原来的ASPX),个人还是喜欢mvc,最近又开始重拾MVC,感觉既熟悉又陌生. 记录一下封装好的分页代码 首先先说下 我使用EF codefirst的目的. 是因为可以有更纯净的代码 不再有EDMX这些东西  而不是真正的用 code first 先有代码 再生成数据库.所以 我虽然使用 的是codefirst 但是本质依然是数据库优先.这个大家可以网上找资料 在基类中写好方法 public class BaseService { pub

sqlserver存储过程----通用分页

下面这个sql是sqlserver中通用分页存储过程: if (exists(select * from sys. procedures where name= 'proc_paging' ))-- 如果 proc_paging这个存储过程存在 drop proc proc_paging  -- 那么就删除这个存储过程 go create proc proc_paging( @pageSize nvarchar ( 50), @currentPage nvarchar ( 50), @table

MySQL 存储过程中分页

2014-11-20 MySQL数据库中,自定义存储过程查询表中的数据,带有分页功能.具体实例如下代码: 1 DROP PROCEDURE IF EXISTS `sampledb`.`proc_GetPagedDataSet`; 2 3 CREATE DEFINER=`root`@`%` PROCEDURE `proc_GetPagedDataSet`( 4 IN tableName VARCHAR (20), /*表名 5 IN pageIndex INT, /*当前页*/ 6 IN page

SQL Server 存储过程进行分页查询

CREATE PROCEDURE prcPageResult -- 获得某一页的数据 -- @currPage INT = 1 , --当前页页码 (即Top currPage) @showColumn VARCHAR(2000) = '*' , --需要得到的字段 (即 column1,column2,......) @tabName VARCHAR(2000) , --需要查看的表名 (即 from table_name) @strCondition VARCHAR(2000) = '' ,

uniquery 配合 mssql 自带存储过程实现分页

--使用系统存储过程实现的通用分页存储过程 -- 此过程原作者,应该是:邹健老前辈 CREATE PROC sp_PageView @sql ntext, --要执行的sql语句 @PageCurrent int=1, --要显示的页码 @PageSize int=10, --每页的大小 @PageCount int OUTPUT --总页数 AS SET NOCOUNT ON DECLARE @p1 int --初始化分页游标 EXEC sp_cursoropen @cursor=@p1 OU