原创

Oracle多表插入

多表插入

insert all
into tab1(t1,t2)
values (t1,t2)
into tab2(t3,t4)
values (t3,t4)
into tab3(t5,t6)
values (t5,t6)
select 1 t1,2 t2,3 t3,4 t4,5 t5,6 t6 from dual;

条件插入

insert all/first
when ots<10000 then into t1
  when ots >=10000 and ots <=20000 then into t2
    when ots >20000 then into t2
select order_id,sum(order_total) ots from oe.orders group by order_id;

insert first:对于每一行数据,只插入到第一个when条件成立的表,不继续检查其他条件。
insert all : 对于每一行数据,对每一个when条件都进行检查,如果满足条件就执行插入操作。
eg:

insert first
when ots < 10000 then into t1
  when ots < 10000 then into t2
    when ots < 10000 then into t3
select order_id,sum(order_total) ots from oe.orders group by order_id;

只插入t1表。

正文到此结束
该篇文章的评论功能已被站长关闭