回答

收藏

Oracle SQL插入with子句

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

我是sql新手,所以也许这是一个愚蠢的问题,但它能吗?With子句与Insert Into一起使用?还是有什么常见的解决方案?我的意思是:
% U. b5 M+ h) k) SWith helper_table As (Select * From dummy2)Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' );谢谢!
& `: t; k; Q0 I& P1 P) V0 {, e我的例子太虚构了,所以我添加了一些扩展代码(到目前为止,答案是thx)。
: ~2 V+ G1 ^: p" P0 ?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                , L6 e, N* J3 y( I$ a* }
    解决方案:                                                               
# f( R/ P' K2 _% D                                                                可根据需要使用多个 helper_tables”。
8 [/ z& }% G6 ^# t. acreate 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 考虑到这一点,您可以通过将表正常连接到主表来完成所有连接
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则