回答

收藏

Oracle SQL插入with子句

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

我是sql新手,所以也许这是一个愚蠢的问题,但它能吗?With子句与Insert Into一起使用?还是有什么常见的解决方案?我的意思是:; h7 T5 a1 f; N1 J/ v0 x) H8 M
With helper_table As (Select * From dummy2)Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' );谢谢!% [" J7 p0 w/ a7 D
我的例子太虚构了,所以我添加了一些扩展代码(到目前为止,答案是thx)。
6 U* N: J- P2 H4 [5 hINSERTINTO    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                - k# z) e$ H5 y% k! c
    解决方案:                                                                + ~* k5 [# m% ~: c% R: R
                                                                可根据需要使用多个 helper_tables”。+ e4 v  o: N" G! L+ J! E$ i
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 考虑到这一点,您可以通过将表正常连接到主表来完成所有连接
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则