ORA-30009: 没有足够的内存用于 CONNECT BY 操作 / ORA-01788: 此查询块中需要 CONNECT BY 子句
Posted
技术标签:
【中文标题】ORA-30009: 没有足够的内存用于 CONNECT BY 操作 / ORA-01788: 此查询块中需要 CONNECT BY 子句【英文标题】:ORA-30009: Not enough memory for CONNECT BY operation / ORA-01788: CONNECT BY clause required in this query block 【发布时间】:2020-01-09 23:00:11 【问题描述】:这里是 Oracle 新手 - 我正在尝试运行插入语句来生成大量数据。
-
原来的查询是这样的:
INSERT INTO HR.fastData (ID)
SELECT 1 + (Level -1) * 1
FROM dual connect by Level < 100000000;
-
收到的第一个错误:
ORA-30009: 没有足够的内存用于 CONNECT BY 操作
我关注了the guidance provided here
修改后的查询:
INSERT INTO HR.fastData (ID)
SELECT 1 + (Level -1) * 1
FROM
(select level from dual connect by Level < 10000),
(select level from dual connect by Level < 10000);
-
我收到的下一个错误:
ORA-01788:此查询块中需要 CONNECT BY 子句
-
修改后的查询现在如下所示:
INSERT INTO HR.fastData (ID)
SELECT 1 + (Level -1) * 1
FROM DUAL CONNECT BY
(select Level from dual connect by Level < 10000),
(select Level from dual connect by level < 10000);
在多次尝试不同的查询变体后,我无法正确执行此操作。我是否正确使用/放置 CONNECT BY
语句?非常感谢任何指导。
谢谢!
【问题讨论】:
语法是connect by [boolean expression]
- 也就是说,在connect by
之后应该有一个计算结果为真或假的表达式,并且将继续添加行,直到它计算为真。 connect by
子句用于分层查询 (connect by prior key = parent_key
),但前段时间发现它可以用作行生成器。其他行发生器结构可用,例如select rownum from xmltable('1 to 10000')
.
【参考方案1】:
看来你要的查询是
SELECT ((lvl1-1)*10) + (lvl2-1) + 1 as ID
FROM (select level as lvl1 from dual connect by Level <= 10000)
CROSS JOIN (select level as lvl2 from dual connect by Level <= 10000);
我不能保证您的系统可以一次性生成所有这些数字,但原则上这是可行的。 Here's a db<>fiddle 表明当每个子查询限制为 10 级时,此查询有效,总共生成 100 行。
【讨论】:
【参考方案2】:var x number;
exec :x := 10;
SELECT level FROM dual connect by level <= :x
union all
select 1 * :x + level from dual connect by level <= :x
union all
select 2 * :x + level from dual connect by level <= :x
union all
select 3 * :x + level from dual connect by level <= :x;
【讨论】:
以上是关于ORA-30009: 没有足够的内存用于 CONNECT BY 操作 / ORA-01788: 此查询块中需要 CONNECT BY 子句的主要内容,如果未能解决你的问题,请参考以下文章
Microsoft Visual Studio 没有足够的内存空间继续执行程序
显示”没有足够的内存来运行此程序.”这是怎么回事 应该怎么设置啊?>