ITPub博客

首页 > 数据库 > Oracle > 非分区表=>分区表(三)

非分区表=>分区表(三)

原创 Oracle 作者:goasktom 时间:2014-05-20 16:59:22 0 删除 编辑
前面已经写了两篇了,今天一高兴在网上又学到一招,其实很简单,就是利用CTAS
大概步骤
1.原表A
2.创建分区表A_NEW(CTAS)
3.将T重命名为A_OLD
4.将A_NEW重命名为A

--表A原来有一条记录

A>select * from a;

        ID
----------
         1

A>create table a_new as select * from a;

Table created.

--现在表A_NEW也有一条记录

A>select * from a_new;

        ID
----------
         1

如果此时向原表A中新插入一条记录,现在表T和T_NEW就不一致了

A>insert into a values(2);

1 row created.

A>select * from a_new;

        ID
----------
         1

A>select * from a;

        ID
----------
         1
         2

A>commit;

Commit complete.

A>rename a to a_old;

Table renamed.

--在两个重命名操作中间,对原表A的访问会失败

A>select * from a;
select * from a
              *
ERROR at line 1:
ORA-00942: table or view does not exist


A>rename a_new to a;

Table renamed.

A>select * from a;

        ID
----------
         1

综上,利用CTAS方式将堆表转换成分区表有两点要注意
1.尽量在闲时操作,以减少数据不一致情况的发生
2.在两个重命名操作中间,对原表的访问会失败

参考:http://edu.21cn.com/oracle/g_50_483124-1.htm

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29646619/viewspace-1165436/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-05-07

  • 博文量
    27
  • 访问量
    43325