sqlserver游标的简单使用
1、第一步:在定义游标之前,需要先定义变量,本示例中只涉及三个需要用到的变量price,sums和name在查询分析器中输入一行代码declare @price float,@sums int,@name nvarchar(10)

3、第三步:打开游标并取一行数据,openc_updateTotalfetch next fromc_updateTotal into @price,@sums,@name

5、第五步:在循环中间添加更新语句来批量对每一行进行修改update product set total =@price*@sums where name=@name

7、第七步:完成,开始执行修改,以下为完整代码declare @price float,@sums int,@name nvar艘早祓胂char(10)declare c_updateTotal cursor forselect price , sums,name from productopen c_updateTotalfetch next from c_updateTotal into @price,@sums,@namewhile @@FETCH_STATUS=0begin--这里处理一些数据update product set total =@price*@sums where name=@namefetch next from c_updateTotal into @price,@sums,@nameendclose c_updateTotaldeallocate c_updateTotal
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:87
阅读量:55
阅读量:41
阅读量:90
阅读量:50