lzzyqxxh 2016-02-01 07:09 采纳率: 33.3%
浏览 1918
已采纳

关于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里查到的。

  • 写回答

2条回答

  • Yiran8935 2016-02-01 07:46
    关注

    大概试验了下 应该是没问题的代码如下
    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;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条