开发者社区> 问答> 正文

关于oracle在一条语句向多个表添加数据

已解决

我这里有t1,t2,t3三个表,当根据t3和t2中的某些条件做出的判断成立时,向t1和t2中添加数据,能不能这么写
insert all
into t1(t1.column1,t1.column2) values(A,B)
into t2(t2.column1,t2.column2) select t3.column1,
t3.column2 from t3
where not exists
(select 1 from t2,t3 where t2.column1=t3.column1
and t2.column2=t3.column2);
大概就是这样子了,t1的数据是具体的字符,t2的数据是从t3里查到的。

展开
收起
51干警网 2016-02-17 22:45:01 2433 0
1 条回答
写回答
取消 提交回答
  • 阿里云论坛版主,QQ 1978638808
    采纳回答

    大概试验了下 应该是没问题的代码如下

    create table student(
    sname varchar2(10) not null,
    sage number(3)
    );
    
    create table course(
    cname varchar2(10) not null,
    cid number(3)
    );
    
    insert into student values('YES',14);
    commit;
    
    select * from student;
    
    insert all
    into student(sname,sage) values('ABC',12)
    into course(cname,cid)
    select t3.sname,
    t3.sage from student t3
    where 2>1;
    commit;
    
    select * from student;
    
    select * from course;
    2019-07-17 18:29:20
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PostgresChina2018_樊文凯_ORACLE数据库和应用异构迁移最佳实践 立即下载
PostgresChina2018_王帅_从Oracle到PostgreSQL的数据迁移 立即下载
Oracle云上最佳实践 立即下载

相关镜像