在存储过程的游标是否可以参与递归?
sbks 2007-04-23 12:22:54 写了一个递归的存储过程,代码中使用到游标,好象该游标不参与递归,因为在试运行时提供该游标已经打开。那就意味着它可能不参于压栈,怎样解决这个问题?
----------
create procedure sp_bomexpand
(
@invcode as varchar(30)
)
/*这是一个递归过程,用来解析物料的最终子件的数量
*/
AS
declare @invid int
declare @zjbm varchar(30)
declare @sl numeric(14,4)
--取出该物料的下级
select @invid=partid from bas_part where invcode=@invcode
--定义游标取出
declare rowno CURSOR FOR select b.invcode,a.baseqtyn from bom_opcomponent a inner join bas_part b on a.componentid=b.partid where componentid=@invid
open rowno
fetch next from rowno into @zjbm,@sl
--开始游标检查---------------------
while @@FETCH_STATUS=0
begin
insert abc_bomend(cpbm,zjbm,sl) values(@invcode,@zjbm,@sl)
exec sp_bomexpand @zjbm
fetch next from rowno into @zjbm,@sl
end
close rowno
deallocate rowno