--声明游标 找开游标 读取游标 关闭游标 删除游标

   create procedure PK_Test
   as
   declare @A_ID nvarchar(20)
   declare @A_Salary float
   --声明游标
   declare mycursor cursor for select A_ID,A_Salary from AddSalry
   open mycursor --打开游标
   --从游标里取出数据库赋值到我们刚才声明的2个变量中
   fetch next from mycursor into @A_ID,@A_Salary
   --判断游标的状态 0 fetch语句成功 -1语句失败 -2不提取的不存在
   while(@@fetch_status=0)
   begin
    print '游标成功的取出一条数据'
    print @A_ID
    print @A_Salary
    --用游标去取下一条记录
    fetch next from mycursor into @A_ID,@A_Salary
   end
   --关闭游标
   close mycursor
   --撤销游标
   deallocate mycursor
   go
   
   
   exec  PK_Test

--那个汉字输格式出现了一点点问题,结果如下

学习游标基础开始

相关文章:

  • 2021-11-13
  • 2021-10-10
  • 2021-09-12
  • 2021-12-30
  • 2021-12-18
  • 2021-12-01
  • 2021-07-22
  • 2021-06-19
猜你喜欢
  • 2022-12-23
  • 2021-04-03
  • 2022-01-17
  • 2022-12-23
  • 2021-12-18
  • 2021-12-02
  • 2022-01-15
相关资源
相似解决方案