SQL Server 中的 CTE 遞迴查詢的上限
T-SQL 的遞迴深度,
Stored Procedure 的最大上限是 32 次
CTE 預設為 100 次,CTE 遞迴的最大上限 32,767 次
Sample:
declare @i_id nvarchar(10);
set @id='0000000001';
with test_sub(id,i_pid,i_level)as
(
select id, i_pid, 0 from [info]
where id=@id
union all
-- 遞迴成員
select a.id, a.i_pid, b.i_level+1
from [info] as a inner join test_sub b on a.i_pid=b.id
)
select * from test_sub
OPTION (MAXRECURSION 150);
go
沒有留言:
張貼留言