存储过程问题

notruiyi 2005-07-07 09:05:51
请问存储过程中能使用游标吗?
如何使用?
begin end中能定义变量吗?

...全文
74 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiushaoye 2005-07-07
  • 打赏
  • 举报
回复
游标性能差,速度慢,还是用别的办法好!
当然可以定义变量,如 declare @v int
notruiyi 2005-07-07
  • 打赏
  • 举报
回复
create procedure ReportBuilder(
@fromDate datetime,
@balanceIn , real)
as
begin

//声明游标,指向比指定日期后的记录
declare buildReportCur SCROLL CURSOR for
select debit,lender ,balance from b_bills

open buildReportCur

declare @debitValue real
declare @lenderValue real
declare @balanceValue real
declare @lastBalance real

set @lastBalance = @balanceIn

FETCH first from buildReportCur into @debitValue,@lenderValue,@balanceValue

while(@@FETCH_STATUS = 0)
begin
set @lastBalance = @lastBalance +@debit- @lenderValue
update buildReportCur set balance = @lastBalance where CURRENT OF buildReportCur
FETCH NEXT from buildReportCur into @debitValue,@lenderValue,@balanceValue
end
end

end
Tongls 2005-07-07
  • 打赏
  • 举报
回复
是可以使用,只是性能比较低,不推荐使用! 尽量使用别的方法解决!

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧