回答

收藏

Oracle SQL插入with子句

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

我是sql新手,所以也许这是一个愚蠢的问题,但它能吗?With子句与Insert Into一起使用?还是有什么常见的解决方案?我的意思是:
0 ~4 d2 Y, h' lWith helper_table As (Select * From dummy2)Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' );谢谢!1 F/ [1 ^% I, w; k$ F3 y
我的例子太虚构了,所以我添加了一些扩展代码(到目前为止,答案是thx)。
, f) i2 j( f- f* iINSERTINTO    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               
( E4 |& e; B2 ^2 t* n. H    解决方案:                                                                / |8 k1 f. h( d) m/ S7 Z7 u: v
                                                                可根据需要使用多个 helper_tables”。( ?# F$ W" e0 K# m0 B
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 考虑到这一点,您可以通过将表正常连接到主表来完成所有连接
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则