sql游标的使用范例
来源:互联网 发布:淘宝广告法投诉处理 编辑:程序博客网 时间:2024/05/17 09:00
关于Sql游标的使用,请看下面的例子就什么都明白了。
declare @id nvarchar(20) --定义变量来保存ID号
declare @A float --定义变量来保存值
declare mycursor cursor for select * from tb_c --为所获得的数据集指定游标
open mycursor --打开游标
fetch next from mycursor into @id,@A --开始抓第一条数据
while(@@fetch_status=0) --如果数据集里一直有数据
begin
select tb_b.name,(tb_b.gz + @A) from tb_b where tb_b.id = @id --开始做想做的事(什么更新呀,删除呀)
fetch next from mycursor into @id,@A --跳到下一条数据
end
close mycursor --关闭游标
deallocate mycursor --删除游标
declare @A float --定义变量来保存值
declare mycursor cursor for select * from tb_c --为所获得的数据集指定游标
open mycursor --打开游标
fetch next from mycursor into @id,@A --开始抓第一条数据
while(@@fetch_status=0) --如果数据集里一直有数据
begin
select tb_b.name,(tb_b.gz + @A) from tb_b where tb_b.id = @id --开始做想做的事(什么更新呀,删除呀)
fetch next from mycursor into @id,@A --跳到下一条数据
end
close mycursor --关闭游标
deallocate mycursor --删除游标
OpenActivity开发中使用的例子:
declare @EmployeeAdditionID bigint
declare @InventoryItemID bigint
declare @Duration nvarchar(50)
declare tmpcursor cursor for select * from EmployeeQualification where Duration is null and InventoryItemID is not null
open tmpcursor
fetch next from tmpcursor into @EmployeeAdditionID,@InventoryItemID,@Duration
while(@@fetch_status=0)
begin
select @Duration = Duration from InventoryItem where InventoryItemID = @InventoryItemID
update EmployeeQualification set Duration = @Duration where (EmployeeAdditionID = @EmployeeAdditionID) and (InventoryItemID = @InventoryItemID)
fetch next from tmpcursor into @employeeAdditionID,@InventoryItemID,@duration
end
close tmpcursor
deallocate tmpcursor
- sql游标的使用范例
- T-SQL游标的使用范例
- 游标的使用范例
- SQL的游标使用规则详解和范例
- .SQL的游标使用规则详解和范例
- SQL SERVER触发器 使用 游标范例
- 游标使用经典范例
- 游标使用范例
- mysql 游标使用范例!!
- sql游标的使用
- SQL游标的使用
- sql游标的使用
- SQL 游标的使用
- sql 游标的使用
- SQL游标的使用
- SQL游标的使用
- sql游标的使用
- SQL游标的使用
- Asp.net中关于Cookie的操作
- 美国之行(二)
- ASP.net时间保存大全
- 下载账号
- Xcode 免证书开发调试(结合网上资料整理)
- sql游标的使用范例
- 记个旧版iOS SDK下载地址
- BAT脚本编写要点(1)_特殊字符
- repeater控件中使用FindControl寻找控件
- php 文件操作1
- 我滴妈呀,哎呀呀,海牙啊啊,这个东西这么无聊啊啊啊,干什么多要积分啊啊啊啊,冬夜动不了啊啊啊啊啊
- subversion安装及使用
- 解决httpd: Could not reliably determine the server's fully qualifi...
- USACO 1.2 两道题目