sqlserver 的一个有游标的过程
程序员文章站
2022-07-05 09:34:46
...
DEALLOCATE c_emp //删除现有的同名游标 //声明一个游标 c_emp declare c_emp cursor for select NEWSTUDENT.IDENTY_NUM,NEWSTUDENT.EXAM_NUM,NEWSTUDENT.STUDENT_NUM from NEWSTUDENT,STUDENT where NEWSTUDENT.STUDENT_NUM=STUDENT.STUDENT_NUM //声明三个变量 declare @IDENTY_NUM nchar(20),@EXAM_NUM nchar(30),@STUDENT_NUM nchar(15) //打开游标 open c_emp //取出数据 fetch c_emp into @IDENTY_NUM,@EXAM_NUM,@STUDENT_NUM
//遍历 while @@fetch_status=0 Begin //更新数据 update STUDENT set IDENTY_NUM=@IDENTY_NUM,EXAM_NUM=@EXAM_NUM where student_num=@STUDENT_NUM //取下一个数据 fetch c_emp into @IDENTY_NUM,@EXAM_NUM,@STUDENT_NUM End close c_emp