CREATEPROCEDURE[dbo].[pro_CURSOR]AS
BEGIN
--声明一个游标
DECLAREMyCURSORCURSORFOR
SELECTuserid,depidFROMusers
--打开游标
openMyCURSOR
--声明两个变量
declare@useridvarchar(50)
declare@depidvarchar(50)
--循环移动
fetchnextfromMyCURSORinto@userid,@depid
while(@@fetch_status=0)
begin
updateuserssetdescription=(selectdep_desfromdepartmentwheredepid=@depid)
whereuserid=@userid
fetchnextfromMyCURSORinto@userid,@depid
end
closeMyCURSOR
deallocateMyCURSOR
END
SQL游标的基本用法
最新推荐文章于 2024-06-29 12:02:59 发布