当前位置:Gxlcms > 数据库问题 > SQL存储过程,使用事务(try catch),游标

SQL存储过程,使用事务(try catch),游标

时间:2021-07-01 10:21:17 帮助过:18人阅读

proc [dbo].[Sys_Rebate_Equity] AS declare @fMemberID varchar(50)--用户ID declare @Rebate decimal(18,2)--总股权数 BEGIN begin try Begin Transaction --开始事务 DECLARE cursor1 CURSOR for --定义游标cursor1 select fMemberID,sum(fNumber) as fNumber from BP_Equity where fNumber>0 group by fMemberID --使用游标的对象 open cursor1 --打开游标 fetch next from cursor1 into @fMemberID,@Rebate --将游标向下移1行,获取的数据放入之前定义的变量@fMemberID,@Rebate中 while @@FETCH_STATUS=0 --判断是否成功获取数据 begin select 1 --进行相应处理 fetch next from cursor1 into @id --将游标向下移1行 end close cursor1 --关闭游标 deallocate cursor1 --删除游标引用 select 888 Commit Transaction --提交事务 End Try Begin Catch if @@trancount > 0 ROLLBACK TRANSACTION --回滚事务 Select 8888 End Catch END

 

SQL存储过程,使用事务(try catch),游标

标签:

人气教程排行