我是新来的sql,所以也许这是一个愚蠢的问题,但有没有可能使用插入到With子句?或者有什么共同的解决方法?我的意思是这样的:Oracle SQL插入到与条款
With helper_table As (
Select * From dummy2
)
Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X');
Thx!
我的例子太虚拟了,所以我添加了一些扩展的代码(thx为迄今为止的答案)。
INSERT
INTO dummy values (a,b) //more values
WITH helper_table AS
(
SELECT *
FROM dummy2
)
WITH helper_table2 AS //from more tables
(
SELECT *
FROM dummy3
)
SELECT t.value as a, t2.value as b
FROM helper_table t
join helper_table t2 on t.value = t2.value //some join
WHERE t.value = 'X' and t2.value = 'X' //other stuff
Thx,它工作正常! :) – user2424380 2011-05-04 15:48:26
临时表可以完成同样的事情吗?例如,使用“create table #t ...”而不是“create table t ...”。我有一个相当复杂的查询,我需要做的,其中的一部分需要不仅仅是立即查询,这就是为什么我需要临时表,但我不想永久写任何东西。谢谢! – 2012-01-12 06:52:20
@MikeWilliamson自#t(临时表),因为您已经描述过它是SQL Server临时表,这是一个oracle表。我可以证明上述语句可以在oracle全局临时表中工作,但这是与SQL Server临时表不同的。我只能推荐你尝试一下,如果上面的语法在SQL Server中适用于普通表插入,我希望它的工作原理相同(注意“期待”并不意味着它会,我也没有尝试过!) – Harrison 2012-01-14 14:21:20