各位老大,请问在SQL Server2000的存储过程中怎样实现递归?

XJEND 2003-07-26 12:29:15
如题
...全文
31 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
XJEND 2003-08-02
  • 打赏
  • 举报
回复
我在里面定义了一个游标后老是出错说游标没有关闭
CrazyFor 2003-08-02
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1375/1375432.xml?temp=.8570978
woyaofengle 2003-07-27
  • 打赏
  • 举报
回复
create proc test11
@id int
as
begin
print @id
set @id = @id -1
if @id > 0
begin
if @@NESTLEVEL<32 --化解超过32层
exec test11 @id
end
end
go
执行:exec test11 42
skywebnet 2003-07-26
  • 打赏
  • 举报
回复
你可以在你自己的存储过程中调用该存储过程自身,但是要求在该存储过程内要有终止条件。
leimin 2003-07-26
  • 打赏
  • 举报
回复
pls see below:
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=70519
txlicenhe 2003-07-26
  • 打赏
  • 举报
回复
create proc test
@id int
as
begin
set @id = @id -1
if @id > 0
print @id
begin
if @@NESTLEVEL<32 --化解超过32层
exec test @id
end
end
go
执行:exec test 20
nboys 2003-07-26
  • 打赏
  • 举报
回复
create proc test11
@id int
as
begin
print @id
set @id = @id -1
if @id > 0
begin
if @@NESTLEVEL<32 --化解超过32层
exec test11 @id
end
end
go
执行:exec test11 42
nboys 2003-07-26
  • 打赏
  • 举报
回复
create proc test
@id int
as
begin
set @id = @id -1
if @id > 0
print @id
begin
if @@NESTLEVEL<32 --化解超过32层
exec test @id
end
end
go
执行:exec test 20
zjcxc 2003-07-26
  • 打赏
  • 举报
回复
不过你要注意,存储过程的最大递归为32层.
zjcxc 2003-07-26
  • 打赏
  • 举报
回复
举个简单的例子:

--创建存储过程aa
create procedure aa @a int
as
print @a
set @a=@a-1
if @a>0
exec aa @a --在存储过程中调用自己


--测试
exec aa 10

--删除测试的存储过程
drop proc aa
caiyunxia 2003-07-26
  • 打赏
  • 举报
回复
用函数

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧