|
||
使用insert语句:
在很多时候,我们会需要对一个表进行插入大量的数据,并且希望在尽 可能短的时间内完成该工作,这里,和大家分享下我平时在做大量数据 insert的一些经验。 前提:在做insert数据之前,如果是非生产环境,请将表的索引和约 束去掉,待insert完成后再建索引和约束。 1.insert into tab1 select * from tab2; commit; 这是最基础的insert语句,我们把tab2表中的数据insert到tab1表中 。根据经验,千万级的数据可在1小时内完成。但是该方法产生的arch 会非常快,需要关注归档的产生量,及时启动备份软件,避免arch目 录撑爆。 2.alter table tab1 nologging; insert /*+ append */ into tab1 select * from tab2; commit; alter table tab1 logging; 该方法会使得产生arch大大减少,并且在一定程度上提高时间,根据 经验,千万级的数据可在45分钟内完成。但是请注意,该方法适合单进 程的串行方式,如果当有多个进程同时运行时,后发起的进程会 有enqueue的等待。注意此方法千万不能dataguard上用(不过要是 在database已经force logging那也是不怕的,呵呵)!! 3.insert into tab1 select /*+ parallel */ * from tab2; commit; 对于select之后的语句是全表扫描的情况,我们可以 加parallel的hint来提高其并发,这里需要注意的是最大并发度受到 初始化参数parallel_max_servers的限制,并发的进程可以通 过v$px_session查看,或者ps -ef |grep ora_p查看。 4.alter session enable parallel dml; insert /*+ parallel */ into tab1 select * from tab2; commit; 与方法2相反,并发的insert,尚未比较和方法2哪个效率更高(偶估 计是方法2快),有测试过的朋友欢迎补充。 5.insert into tab1 select * from tab2 partition (p1); insert into tab1 select * from tab2 partition (p2); insert into tab1 select * from tab2 partition (p3); insert into tab1 select * from tab2 partition (p4); 一些特别实用的"SQL"语句: SQL: select * into b from a where 1<>1 ◆说明:拷贝表(拷贝数据,源表名:a 目标表名:b) SQL: insert into b(a, b, c) select d,e,f from b; ◆说明:显示文章、提交人和最后回复时间 SQL: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b ◆说明:外连接查询(表名1:a 表名2:b) SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c ◆说明:日程安排提前五分钟提醒 SQL: select * from 日程安排 where datediff('minute',f开始时 间,getdate())>5 ◆说明:两张关联表,删除主表中已经在副表中没有的信息
|
|
|
设为首页 | 网站地图 | English Version | Tranditional Chinese | 合作伙伴 | 隐私保护 | 版权声明 | 商业合作 | 联系我们 |
| 直拨:021-52730141 公司地址:上海市长宁区武夷路697号倍益商务中心409室 邮编:200051 服务信箱:datarecovery@163.com 客服QQ:363659622 Copyright 上海盘夫数据恢复中心版权所有 |