---游標更新刪除當前數據 ---1.聲明游標 declare orderNum_03_cursor cursor scroll for select OrderId ,userId from bigorder where orderNum='ZEORD003402' --2.打開游標 open o... ...
---游標更新刪除當前數據 ---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 orderNum_03_cursor --釋放 DEALLOCATE orderNum_03_cursor