oracle备份表几张表,oracle对一个大表的备份



业务介绍:

index_data_test一个有8亿行数据的表,有联合索引,其中有2014年(每天几百万,20150401日期字段)的数据(5亿行)和2015的数据(3亿行),下面是把2014年的数据备份到另外一个表里

以下是开发过程的主要流程:

v_flow:='1002';--备份物理网格数据

select count(1)

into v_flagnum

from index_data_test

where acct_date >= v_day_begin

and acct_date <= v_day_end;

--如果有需要备份的数据,才需要后续处理

if v_flagnum>0  then

begin

execute immediate 'drop table index_data_test_tmp1';

exception when others then

null;

end;

--将需要备份的数据存入临时表

v_flow:='100201';

execute immediate '

create table index_data_test_tmp1 nologging parallel 8 as

SELECT /*+ parallel(c,8) */

acct_date,

province_code,

eparchy_code,

city_code,

dgrid_id,

pgrid_id,

index_code,

dvalue,

ldvalue,

mtotalvalue,

lmdvalue

from index_data_test

where acct_date >='|| v_day_begin||' and  acct_date <='|| v_day_end   ;

begin

execute immediate 'drop table index_data_test_tmp2';

exception when others then

null;

end;

--备份最新数据

v_flow:='100202';

execute immediate '

create table index_data_test_tmp2 nologging parallel 8 as

SELECT /*+ parallel(c,8) */

acct_date,

province_code,

eparchy_code,

city_code,

dgrid_id,

pgrid_id,

index_code,

dvalue,

ldvalue,

mtotalvalue,

lmdvalue

from index_data_test

where acct_date > ' ||v_day_end ;

v_flow:='100202';

--插入到备份表

v_flow:='100203';

execute immediate '

INSERT INTO index_data_test_bak nologging

SELECT /*+ parallel(a,8) */

acct_date,

province_code,

eparchy_code,

city_code,

dgrid_id,

pgrid_id,

index_code,

dvalue,

ldvalue,

mtotalvalue,

lmdvalue

FROM index_data_test_tmp1 a ';

COMMIT;

--删掉正式表

execute immediate ' drop table index_data_test ';

--创建正式表      v_flow:='100204';      execute immediate '      create table index_data_test nologging parallel 8 as      SELECT /*+ parallel(c,8) */            acct_date,            province_code,            eparchy_code,            city_code,            dgrid_id,            pgrid_id,            index_code,            dvalue,            ldvalue,            mtotalvalue,            lmdvalue       from index_data_test_tmp2  ';             --给正式表创建索引       v_flow:='100205';       execute immediate '       create index PK_index_data_test_0655 on index_data_test (ACCT_DATE, PGRID_ID, INDEX_CODE)       tablespace GRID_INDX_02       pctfree 10       initrans 2       maxtrans 255       storage       (         initial 64K         next 1M         minextents 1         maxextents unlimited       )';         --删除临时表        execute immediate 'drop table index_data_test_tmp1';        execute immediate 'drop table index_data_test_tmp2';  else        --删除临时表        execute immediate 'drop table index_data_test_tmp1';  end if;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值