---游标更新删除当前数据
---1.声明游标
declare orderNum_03_cursor cursor scroll
for select OrderId ,userId from bigorder where orderNum='ZEORD003402'
--2.打开游标
open orderNum_03_cursor
--3.声明游标提取数据所要存放的变量
declare @OrderId int ,@userId varchar(15)
--4.定位游标到哪一行
fetch First from orderNum_03_cursor into @OrderId,@userId --into的变量数量必须与游标查询结果集的列数相同
while @@fetch_status=0 --提取成功,进行下一条数据的提取操作
begin
if @OrderId=122182
begin
Update bigorder Set UserId='123' Where Current of orderNum_03_cursor --修改当前行
end
if @OrderId=154074
begin
Delete bigorder Where Current of orderNum_03_cursor --删除当前行
end
fetch next from orderNum_03_cursor into @OrderId ,@userId --移动游标
end
--关闭游标语法
close [ Global ] cursor_name | cursor_variable_name
--关闭游标
close orderNum_03_cursor
转载于:https://www.cnblogs.com/starts/p/5179119.html