怎么把这段游标使用递归写出来 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)
就是这段游标用递归优化
展开
 我来答
匿名用户
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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式