我有两个表格,一个是齿轮,另一个是齿轮轴。
随着我的链轮制造业务的增长,决定哪些链轮需要齿轮的业务逻辑将变得更加复杂。因此,我想使用一系列临时表来过滤掉非候选链轮。我认为这比没有注释的一行语句更易于维护。
如果我将最后一行更改为
单行插入语句可以工作,而多行插入语句无法工作。 我唯一看到的区别是后者从临时表中获取其值。
为什么我不能从临时表中插入行?
create table sprockets(
id NUMBER
);
INSERT into sprockets VALUES (4);
INSERT into sprockets VALUES (8);
INSERT into sprockets VALUES (15);
INSERT into sprockets VALUES (16);
INSERT into sprockets VALUES (23);
INSERT into sprockets VALUES (42);
create table cogs(
id NUMBER
);
我想从sprockets
中取出一些id,并将它们放入cogs
中。
insert into cogs select id from sprockets s where s.id < 40 and MOD(s.id, 3) != 0;
这将按预期向 cogs
添加齿轮 4、8、16、23。
4 rows inserted
随着我的链轮制造业务的增长,决定哪些链轮需要齿轮的业务逻辑将变得更加复杂。因此,我想使用一系列临时表来过滤掉非候选链轮。我认为这比没有注释的一行语句更易于维护。
--sprockets with ids greater than 40 are too big to frob,
--so it's impossible to weld a cog to them
with frobbableSprockets as(
select id from sprockets where sprockets.id < 40
),
--non-greppable sprockets have built-in harmonic oscillators,
--so cogs are not required
greppableFrobbableSprockets as(
select id from frobbableSprockets f where MOD(f.id,3) != 0
),
--not pictured: more filtering using arcane business logic,
--including but not limited to:
--whether it is raining on a tuesday,
--and if the moon is in the seventh house.
--sprockets with ids less than 3 are from the legacy system and already have cogs
sprocketsRequiringCogs as(
select id from greppableFrobbableSprockets f where f.id > 3
)
insert into cogs select id from sprocketsRequiringCogs
这段代码相对易读,但不幸的是它并不能正常工作!
insert into cogs select id from sprocketsRequiringCogs
Error at Command Line:18 Column:2
Error report:
SQL Error: ORA-00928: missing SELECT keyword
如果我将最后一行更改为
select id from sprocketsRequiringCogs
,则没有错误,因此我知道问题必须在插入语句中而不是临时表的声明中。单行插入语句可以工作,而多行插入语句无法工作。 我唯一看到的区别是后者从临时表中获取其值。
为什么我不能从临时表中插入行?
*
。 - Justin Skiles