怎么把这段游标使用递归写出来 15
declarecursor_abapartcursorforselecta.partnofromabaproddocuawhere(@fpartno=''orpartno...
declare cursor_abapart cursor for select a.partno from abaproddocu a where (@fpartno='' or partno>=@fpartno) and (@tpartno='' or partno<=@tpartno) and="" fpartdesc="" or="" a.partdesc="" like="" fmattpno="" a.mattpno="">=@fmattpno) and (@tmattpno ='' or a.mattpno<=@tmattpno)and partno in (select b.partno from ababomi b) order by a.partno open cursor_abapart fetch next from cursor_abapart into @tmppart while (@@fetch_status=0)
就是这段游标用递归优化 展开
就是这段游标用递归优化 展开
1个回答
2015-12-13
展开全部
把游标声明为局部的即可,即加上local
declare dwbm_cur cursor LOCAL FOR
CREATE procedure dgdwbmproc @dwbm varchar(15), @jb varchar(1)
AS
declare @ybdwbm varchar(15), @ybdwmc varchar(50), @ybjb varchar(1)
declare dwbm_cur cursor LOCAL FOR
SELECT DWBM, DWMC, JB FROM DWBM WHERE DWBM LIKE @dwbm + '%' AND JB = @jb + 1
if(SELECT count(*) FROM DWBM WHERE DWBM LIKE @dwbm + '%' AND JB = @jb + 1) > 0
begin
open dwbm_cur
fetch next FROM dwbm_cur INTO @ybdwbm, @ybdwmc, @ybjb
while @@fetch_status = 0
begin
SELECT @ybdwbm, @ybdwmc, @ybjb
execute dgdwbmproc @ybdwbm, @ybjb
fetch next FROM dwbm_cur INTO @ybdwbm, @ybdwmc, @ybjb
end
close dwbm_cur
deallocate dwbm_cur
declare dwbm_cur cursor LOCAL FOR
CREATE procedure dgdwbmproc @dwbm varchar(15), @jb varchar(1)
AS
declare @ybdwbm varchar(15), @ybdwmc varchar(50), @ybjb varchar(1)
declare dwbm_cur cursor LOCAL FOR
SELECT DWBM, DWMC, JB FROM DWBM WHERE DWBM LIKE @dwbm + '%' AND JB = @jb + 1
if(SELECT count(*) FROM DWBM WHERE DWBM LIKE @dwbm + '%' AND JB = @jb + 1) > 0
begin
open dwbm_cur
fetch next FROM dwbm_cur INTO @ybdwbm, @ybdwmc, @ybjb
while @@fetch_status = 0
begin
SELECT @ybdwbm, @ybdwmc, @ybjb
execute dgdwbmproc @ybdwbm, @ybjb
fetch next FROM dwbm_cur INTO @ybdwbm, @ybdwmc, @ybjb
end
close dwbm_cur
deallocate dwbm_cur
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询