Oracle_学习使用SQL语四(DML语句)

[b]一、insert插入数据[/b]
[b]1、将整张表的数据插入到一张表中[/b]
[color=red] 语法:insert into 表名(子查询)[/color]
使用子查询将整张表插入到制定的表中,有两种方式,如下:
(1)、insert into cip_test (select *from cip_tmp)。
(2)、insert /*+append*/into cip_test (select *from cip_tmp);
[color=red]注意:如果要插入大量的数据,则采用第二种方式,效率高于第一种,insert数据会直接加到表的最后面,而不会在表的空闲块中插入数据,使用append会增加数据插入的速度。网上说"append 属于direct insert,归档模式下append+table nologging会大量减少日志,非归档模式append会大量减少日志,append方式插入只会产生很少的undo
",有点不明白,待研究。我按照第二种方法插入50000条数据,结果toad死掉了,不知道为什么。[/color]
[b]2、将整张表的输入插入到多个表中[/b]
[b](1)、使用all操作符执行插入操作[/b]
使用insert语句可以将某张表的数据同时插入到多张表中,语法如下:
[color=red] insert all insert_into_clause[value_clause] 子查询;
如上所示:insert_into_clause指insert子句,value_clause指定值子句[/color]
insert all into cip_test into cip_temp select * from cip_tmp where id<10;

[color=blue]插入的数据中cip_test表中的数据为1—10,cip_temp表中的数据为1—10,cip_temps表中的数据为1—10。[/color]
insert  all 
when id between 1 and 10 then into cip_test
when id between 11 and 20 then into cip_temp
when id between 21 and 30 then into cip_temps
select * from cip_tmp where id<30;

[color=blue]插入的数据中cip_test表中的数据为1—10,cip_temp表中的数据为11—20,cip_temps表中的数据为21—30。[/color]
[color=red]注意:SQL语法1是将查询的信息全部插入的指定的表中。SQL2语句2是将查询的结果按照条件插入到指定的表中。[/color]
[b](2)、使用first操作符执行插入操作[/b]
当使用first操作符插入多表数据时,当先前条件已经满足,并且已经插入到表中,则该数据在后续插入中将不会在被用到。代码例如:
insert  first
when id <=10 then into cip_test
when id <=20 then into cip_temp
when id <=30 then into cip_temps
select * from cip_tmp where id<30;

[color=blue]插入的数据中cip_test表中的数据为1—10,cip_temp表中的数据为11—20,cip_temps表中的数据为21—30。[/color]
[b]二、update更新数据[/b]
当使用update语句更新数据时,不仅可以使用表达式、数值直接更新数据,可可以使用子查询更新数据,某些情况下使用子查询更新效率更好,例如:
update cip_temp set (name,age,address)=(select name,age,address from cip_test where id=1) where id=20;[/code
[b]三、delete删除数据[/b]
当使用delete语句删除数据时,可以在where子句中指定值,并根据条件删除数据,另外也可以再where子句中使用子查询做为条件删除数据,例如:
[code="Oracle"]delete from cip_temp where name=(select name from cip_test where id=1)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值