• 使用游标循环读取数据表并打印出来


    declare @AppliedIndustryNO varchar(20) --定义一个变量
    declare @AppliedIndustryName varchar(20) --定义一个变量
    use ISPDB--引用数据库
    Declare MyCusror_T_AppliedIndustry Cursor Scroll --定义建立一个游标变量
          For Select * From T_AppliedIndustry Order By AppliedIndustryNO --读取数据表
          Open MyCusror_T_AppliedIndustry --打开游标
          Fetch next From MyCusror_T_AppliedIndustry --执行取数操作
                Into @AppliedIndustryNO,@AppliedIndustryName  
                While(@@Fetch_Status = 0)--检查状态
                      Begin
                             Begin
                                   Select @AppliedIndustryNO = Convert(varchar(20),@AppliedIndustryNO)
                                   Select @AppliedIndustryName = Convert(varchar(20),@AppliedIndustryName)
                                   PRINT @AppliedIndustryNO + ':' + @AppliedIndustryName --打印数据字段
                             End
    
                             Fetch next From MyCusror_T_AppliedIndustry
                             Into @AppliedIndustryNO,@AppliedIndustryName --给变量赋值
                      End
                Close MyCusror_T_AppliedIndustry --关闭游标
                Deallocate MyCusror_T_AppliedIndustry --释放游标
       GO
    
    --修改当前游标的数据方法如下:
      declare @AppliedIndustryName varchar(20)
      UpDate T_AppliedIndustry Set @AppliedIndustryName = '移动' Where Current Of MyCusror_T_AppliedIndustry;
    --      删除当前游标行数据的方法如下: 
                Delete From T_AppliedIndustry Where Current Of MyCusror_T_AppliedIndustry
          Select @@CURSOR_ROWS 
    --可以得到当前游标中存在的数据行数。注意:此变量为一个连接上的全局变量,因此只对应最后一次打开的游标。
    
    use job --引用数据库名
    declare@namevarchar(20) --定义一个变量 如果打印读取多个就要定义多个变量
    declare@Sexvarchar(20)

    DECLARE Student_Cursor CURSORFOR--定义一个游标变量
    SELECT Name ,Sex FROM Student --读取数据表
    OPEN Student_Cursor --打开游标
    FETCHNEXTFROM Student_Cursor into@name, @Sex--执行取数操作
    WHILE@@FETCH_STATUS=0--检查状态
    BEGIN
    print@name+@Sex; --打印数据字段

    FETCHNEXTFROM Student_Cursor into@name ,@Sex--执行取数操作

    END;
    CLOSE Student_Cursor;--关闭游标
    DEALLOCATE Student_Cursor; --释放游标
    GO
  • 相关阅读:
    The Android ION memory allocator
    ffmpeg 从mp4上提取H264的nalu
    annexb模式
    算法优化:rgb向yuv的转化最优算法
    Android平台上PMEM的使用及Platform设备注册(二)
    Android平台上PMEM的使用及Platform设备注册(一)
    ffmpeg教程
    视频编解码学习之四:视频处理及编码标准
    深入浅出:了解jsonp跨域的九种方式
    前端小知识集锦
  • 原文地址:https://www.cnblogs.com/Warmsunshine/p/1958449.html
Copyright © 2020-2023  润新知