How and where do I set the MAXRECURSION option?(如何以及在何处设置 MAXRECURSION 选项?)
问题描述
我有一个查询,它耗尽了默认的 MAXRECURSION
限制 100.给我以下错误消息:
I have a query that exhausts the default MAXRECURSION
limit of 100. Giving me the following error message:
语句终止.最大递归 100 在语句完成前已用完.
The statement terminated. The maximum recursion 100 has been exhausted before statement completion.
我发现我需要使用 OPTION (MAXRECURSION xxx)
来提高这个 CTE 的限制,但我不知道把它放在哪里.
I have found out that I need to raise the limit for this CTE using OPTION (MAXRECURSION xxx)
but I don't know where to put this.
到目前为止,我已经尝试将它放在我定义 CTE 的位置旁边,但它不起作用.我也试过几个不同的地方,它也不起作用.我每次得到的错误是:
So far I've tried to put it next to where I define the CTE but it isn't working. I've also tried a few different places and it's not working either. The error I get each time is:
关键字OPTION"附近的语法不正确.
Incorrect syntax near the keyword 'OPTION'.
那么我应该将 OPTION (MAXRECURSION XXX)
命令放在我的 SQL 中的什么位置?
So where should I put the OPTION (MAXRECURSION XXX)
command in my SQL?
with
tab (id,start,en) AS (
SELECT 1, 100, 200
UNION ALL SELECT 2, 200, 500
),
cte (id,start,en) AS (
SELECT id, start, en FROM tab
UNION ALL
SELECT id, start+1, en FROM cte WHERE start+1 <= en
)
SELECT id, start
FROM cte
ORDER BY id
推荐答案
with tab AS
(
select 1 as id, 100 as start, 200 as en
union all
select 2, 200, 500),
cte AS
(
select id,start,en from tab
union all
select id,start+1 , en from cte where start+1<=en
)
SELECT id,start from cte
order by id
OPTION (MAXRECURSION 1000)
这篇关于如何以及在何处设置 MAXRECURSION 选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以及在何处设置 MAXRECURSION 选项?
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- 导入具有可变标题的 Excel 文件 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01