加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle SQL插入到With子句

发布时间:2020-12-12 13:51:59 所属栏目:百科 来源:网络整理
导读:我是新来的sql,所以也许这是一个愚蠢的问题,但有可能使用With子句插入吗?还是有任何常见的解决方法?我的意思是这样的: With helper_table As (Select * From dummy2)Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' ); 谢
我是新来的sql,所以也许这是一个愚蠢的问题,但有可能使用With子句插入吗?还是有任何常见的解决方法?我的意思是这样的:
With helper_table As (
Select * From dummy2
)
Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' );

谢谢!

我的例子太虚拟了,所以我添加了一些扩展代码(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
您可以根据需要使用尽可能多的’helper_tables’。
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 <10),h1 as (select lvl,lvl/1.5 hp from de),h2 as (select lvl,lvl/2 hp2 from de)
select h1.hp,h2.hp2,de.lvl
  from de 
        inner join
       h1 on de.lvl = h1.lvl
        inner join
       h2 on de.lvl = h2.lvl
/

考虑到这一点,您可以通过正常加入表到主表来完成所有的连接

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读