mysql分页存储过程 分页查询语句_分页存储过程(用存储过程实现数据库的分页代码)...

用存储过程实现数据库的分页代码,加快页面执行速度。具体的大家可以测试下。

--*******************************************************

--* 分页存储过程 *

--* 撒哈拉大森林 *

--* 2010-6-28 *

--*******************************************************

if exists(select * from sysobjects where type='P' and name=N'P_Paging')

drop procedure P_Paging

go

create procedure P_Paging

@SqlStr nvarchar(4000), --查询字符串

@CurrentPage int, --第N页

@PageSize int --每页行数

as

set nocount on

declare @P1 int, --P1是游标的id

@rowcount int

exec sp_cursoropen @P1 output,@SqlStr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output

select ceiling(1.0*@rowcount/@PageSize) as 总页数--,@rowcount as 总行数,@CurrentPage as 当前页

set @CurrentPage=(@CurrentPage-1)*@PageSize+1

exec sp_cursorfetch @P1,16,@CurrentPage,@PageSize

exec sp_cursorclose @P1

set nocount off

go

----创建测试表

--if exists(select * from sysobjects where type='U' and name=N'Test_Students')

-- drop table Test_Students

--go

--create table Test_Students(

-- id int IDENTITY(1,1) not null,

-- name nvarchar(100) not null

--)

--

----创建测试数据

--declare @i int

--set @i = 100000

--while @i>0

-- begin

-- insert into Test_Students values('姓名')

-- set @i = @i - 1

-- end

--

----执行存储过程

--exec P_Paging 'select * from Test_Students order by id',100,100 --执行

--

----删除测试表

--if exists(select * from sysobjects where type='U' and name=N'Test_Students')

-- drop table Test_Students

--go

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值