ALTERPROCEDURE [dbo].[cursor_test] AS BEGIN DECLARE@data1int--声明变量 DECLARE@data2int--声明变量 DECLARE@data3int--声明变量 DECLARE@idint--声明变量
DECLARE cursor_test CURSORFOR--创建游标
SELECT id,test1,test2,test3 FROM test --查询语句
OPEN cursor_test --打开游标
FETCH NEXT FROM cursor_test into@id,@data1,@data2,@data3--从游标变量中读取值
WHILE @@FETCH_STATUS=0--判断FETCH语句是否执行成功
BEGIN --select "data1" = @data1,"data2" = @data2,"data3" = @data3 --输出数据 update test set test1=@data1+1,test2=@data2+1,test3=@data3+1where id=@id FETCH NEXT FROM cursor_test into@id,@data1,@data2,@data3-- 从游标中重新读取值