回答

收藏

Oracle SQL插入with子句

技术问答 技术问答 224 人阅读 | 0 人回复 | 2023-09-14

我是sql新手,所以也许这是一个愚蠢的问题,但它能吗?With子句与Insert Into一起使用?还是有什么常见的解决方案?我的意思是:
+ U* n$ O; B; D9 W; C9 w) x* H- gWith helper_table As (Select * From dummy2)Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' );谢谢!
8 e4 G% F6 O; I+ ^9 Y. ]我的例子太虚构了,所以我添加了一些扩展代码(到目前为止,答案是thx)。4 J9 [/ [6 d5 A+ g% B
INSERTINTO    dummy values (a,b)  //more valuesWITH    helper_table AS   SELECT  *    FROM    dummy2    )WITH    helper_table2 AS   //from more tables   SELECT  *    FROM    dummy3     SELECT  t.value as a,t2.value as bFROM    helper_table t join helper_table t2 on t.value = t2.value //some joinWHERE   t.value = 'X' and t2.value = 'X other stuff               
( U3 @% ?8 x7 O7 [( R9 o" z1 y    解决方案:                                                               
2 M# V, V9 F% z4 P' Q                                                                可根据需要使用多个 helper_tables”。6 t1 d+ l+ ]. d. [+ h
create table t(helper1 varchar2(50) ,helper2 varchar2(50) ,dataElement varchar2(50) );insert into t(helper1,helper2,dataelement)with     de as(select level lvl from dual connect by level 考虑到这一点,您可以通过将表正常连接到主表来完成所有连接
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则