oracle insert all 复合表插入

前端之家收集整理的这篇文章主要介绍了oracle insert all 复合表插入前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

insert all (复合表插入),是将一个查询结果同时插入多个表中的功能。使用insert all的好处是通过读取一次源表就可以插入多张目标表,减少重复读取的开销。

语法:

INSERT [ALL] [conditional_insert_clause]

[insert_into_clause value_clause] (subquery);


conditional_insert_clause is:

[ALL] [FIRST]

[WHEN condition THEN] [insert_into_clause value_clause]

[ELSE] [insert_into_clause value_clause]


all:不考虑先后关系,只要满足条件,就全部插入;
first:考虑先后关系,如果有数据满足第一个when条件又满足第二个when条件,则执行第一个then插入语句,第二个then就不插入第一个then已经插入过的数据了。
其区别也可描述为,all只要满足条件,可能会作重复插入;first首先要满足条件,然后筛选,不做重复插入


示例:

@H_301_38@insertall whenc1<1000thenintosamall_ordersvalues(oid,c1,sid,cid) whenc1<2000thenintomedium_ordersvalues(oid,cid) whenc1>2000andc1<2900thenintolarge_ordersvlaues(oid,cid) elseintospecial_orders selectoid,cid fromorders;


指定insert first 当第一个when条件成立时,执行该when条件后的语句,并且跳过后面的 WHEN 子句(后面的when语句都不再考虑满足第一个When子句的记录,即使该记录满足when语句中的条件)。

@H_301_38@insertfirst whenc1<1000thenintosamall_ordersvalues(oid,cid fromorders;


上面两条语句区别在第二个when条件,insert all 中 第二个条件会插入orders 表中c1<2000的记录,insert first 中第二个when条件会插入orders表中1000<c1<2000的记录,insert first中插入第二个when子句中的表时排除了第一个when条件的记录,

原文链接:https://www.f2er.com/oracle/207144.html

猜你在找的Oracle相关文章