存储过程用游标的方式写出来怎么写

create or replace procedure p_lx is
begin
UPDATE AB01_QHD1 t set t.w =1 where t.name in (select t.name from AB01_QHD1 t,AA01_QHD2 t2 where t.name=t2.name);
commit;

end p_lx;

用游标写怎么写 实现上面的代码

1个回答

create procedure p_lx
as
begin
declare @bianliang varchar(50) ;
set @bianliang='';
declare cur cursor fast_forward for
select t.name from AB01_QHD1 t join AA01_QHD2 t2 on t.name=t2.name
open cur
fetch next from cur into @bianliang
while @@fetch_status=0
begin
UPDATE AB01_QHD1 set w =1 where name=@bianliang
fetch next from cur into @bianliang
end
close c ur
deallocate cur
end
go

这是SQL SERVER的实现方式。你这个不需要写存储过程或者游标的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问