SQL中游標嵌套循環(huán)的示例
SQL中經(jīng)常要用到循環(huán),下面就將為您介紹SQL中游標嵌套循環(huán)的示例,供您參考,希望對您學(xué)習(xí)SQL的循環(huán)有所幫助。
create table #temp(a int,b int)
insert into #temp
select 1,2
insert into #temp
select 3,4
select * from #temp
declare @i int,
@j int
declare cur1 cursor for
select a from #temp
open cur1
fetch cur1 into @i
while @@fetch_status =0
begin
select 'cur1:',@i
declare cur2 cursor for
select b from #temp
open cur2
fetch cur2 into @j
while @@fetch_Status =0
begin
select 'cur2:',@j
fetch cur2 into @j
end
close cur2
deallocate cur2
fetch cur1 into @i
end
close cur1
drop table #temp
deallocate cur1
【編輯推薦】