Oracle

xiaoxiao2024-05-08  24

[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)
转载请注明原文地址: https://www.6miu.com/read-5015246.html

最新回复(0)