set @cr1 = cursor for select aa from tb_a open @cr1 fetch next from @cr1 into @aa while @@fetch_status = 0 begin set @cr2 = cursor for select bb form tb_b open @cr2 fetch next from @cr2 into @bb begin .... fetch next from @cr2 into @bb end close @cr2 deallocate @cr2 ..... fetch next from @cr1 into @aa end close @cr1 deallocate @cr1
select aa from tb_a
open @cr1
fetch next from @cr1 into @aa
while @@fetch_status = 0
begin
set @cr2 = cursor for
select bb form tb_b
open @cr2
fetch next from @cr2 into @bb
begin
....
fetch next from @cr2 into @bb
end
close @cr2
deallocate @cr2
.....
fetch next from @cr1 into @aa
end
close @cr1
deallocate @cr1
频繁使用会影响程序的运行速度。