IT培训网 - IT职场人学IT技术上IT培训网
数据库小常识 聊聊insert all和insert first语句用法
时间:2019-04-29 13:22:15 来源:编程网 作者:IT培训网 已有:名学员访问该课程
数据库中,insert all和insert first语句,是用于按给定条件同时向多个表插入数据,两者有什么区别呢?IT培训网和你一起聊数据库小常识,让你清楚了解insert all和insert first语句用法,如下所示:记录了两者的用法和区别。

简述insert all和insert first用法
1、无条件insert all
用于不分条件的向几个表同时插入一批数据。
建立测试表
create table t1(a number, b varchar2(20));
insert into t1 values(1, 'aaa');
insert into t1 values(2, 'bbb');
insert into t1 values(3, 'ccc');
commit;
create table t2(a number, b varchar2(20));
create table t3(a number, b varchar2(20));
create table t4(a number, b varchar2(20));
从第一个表中获取数据,并同时写入其它几个表,各个表可以有不同的值
insert all into t2 values (a + 1, b)
into t3 values (a + 2, b)
select a, b from t1;
commit;
如果各个表插入的数据一样,则以上还可以简化
insert all into t2
into t3
select a, b from t1;
commit;
2、有条件insert all
根据查询数据的不同值,分别插入不同表
insert all when a >=1 then
into t2
when a >=2 then
into t3
else
into t4
select a, b from t1;
commit;
观察几个表的查询结果
select * from t1;
A B
1 aaa
2 bbb
3 ccc
select * from t2;
A B
1 aaa
2 bbb
3 ccc
select * from t3;
A B
2 bbb
3 ccc
select * from t4;
未选定行
3、有条件insert first
如果第一个when子句的值为true,对于给定的行执行相应的into子句,并且跳过后面的when子句,后面的插入语句不再执行
insert first when a >=1 then
into t2
when a >=2 then
into t3
else
into t4
select a, b from t1;
commit;
观察表的查询结果
select * from t1;
A B
1 aaa
2 bbb
3 ccc
select * from t2;
A B
1 aaa
2 bbb
3 ccc
select * from t3;
未选定行
select * from t4;
未选定行
每期开班座位有限.0元试听抢座开始!
温馨提示 : 请保持手机畅通,咨询老师为您
提供专属一对一报名服务。
- 上一篇:西安CAD制图培训班在哪里
- 下一篇:视频的制作用什么软件 视频制作软件哪个强大





简述计算机含金量高的证
CCNA是什么认证 CCNA培训一
cda和cpda两者有什么区别
什么是CCIE认证 CCIE认证有
有关MySQL备份和恢复策略详
怎样考取华为认证网络工
华为hcna认证含金量高吗
红帽RHCSA认证是什么 红帽
美工设计需要掌握哪些工
计算机等级考试和软考两
ACAA证书有用吗 ACAA UI设计师证书含
微软MTA认证有用吗 微软MTA证书含
学人工智能10本必看书 人工智能入
晚自习对提升IT技能有帮助吗
从IT培训网毕业可以获得什么证书
如何卸载mysql 图文教程教你完全卸