使用游标更新表中数据
2007-08-24 00:46
417 查看
(注:其中RemoteServer为定义的一个链接服务器)
declare mycursor2 cursor forward_only static
for select ProductId,ProductName from RemoteServer.northwind.dbo.products
declare @pid1 int,@pid2 int,@pname1 nvarchar(40),@pname2 nvarchar(40)
open mycursor2
fetch next from mycursor2 into @pid2,@pname2
while @@fetch_status=0
begin
update products set productname=@pname2 where productid=@pid2
fetch next from mycursor2 into @pid2,@pname2
end
close mycursor2
deallocate mycursor2
declare mycursor2 cursor forward_only static
for select ProductId,ProductName from RemoteServer.northwind.dbo.products
declare @pid1 int,@pid2 int,@pname1 nvarchar(40),@pname2 nvarchar(40)
open mycursor2
fetch next from mycursor2 into @pid2,@pname2
while @@fetch_status=0
begin
update products set productname=@pname2 where productid=@pid2
fetch next from mycursor2 into @pid2,@pname2
end
close mycursor2
deallocate mycursor2
相关文章推荐
- SQL 游标的使用(更新数据)
- 使用游标逐行更新数据
- [MSSQL]存储过程示例(拷贝数据表--游标使用--更新数据-日期函数的使用)
- MySql 使用存储过程和游标读取并更新数据
- Mysql游标使用 批量插入或更新数据
- 游标操作,使用游标,更新数据
- Oracle使用游标更新数据
- 使用游标将excel不同表的列关联,并根据两表间相同的列值逐行更新数据
- 使用游标批量更新数据
- SQL中游标使用--遍历数据逐行更新:相当于for循环
- ORACLE使用游标更新数据
- Oracle 10g使用游标更新或删除数据
- 关于使用游标更新数据和Case语句进行更新的实现过程
- 使用游标更新和删除数据
- Oracle 10g使用游标更新或删除数据
- 使用游标——使用游标更新或删除数据
- Mysql创建存储过程,使用游标Cursor循环更新
- 使用Sqlserver更新锁防止数据脏读
- oracle更新大量数据太慢,可以通过游标实现的例子
- 使用MyBatis批量更新数据到Oracle的表中