本文参考来自作者:蓝紫

详细内容请阅读原文 : http://www.cnblogs.com/lanzi/archive/2013/01/24/2875838.html

在oracle 11.2环境下测试

--drop table tab_a purge;

--创建分区表

create table tab_a

(

r_id number(19) primary key,

r_name varchar2(300),

r_pat  integer

)

partition by list (r_pat)

(

partition p_value1 values(1),

partition p_value2 values(2),

partition p_value3 values(3),

partition p_def values(default)

)

;

--创建普遍表

create table tab_b as select * from tab_a;

--创建主键

alter table tab_b add primary key(r_id);

---插入测试数据

insert into tab_a

(r_id,r_name,r_pat)

select a.OBJECT_ID,a.OBJECT_NAME,1 from all_objects a;

insert into tab_a select  99199999,'test',1 from dual;

commit;

--测试分区交换

----1.分区表,创建了主键索引,普通表没有创建,则

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation

--ORA-14097: ALTER TABLE EXCHANGE PARTITION 中的列类型或大小不匹配

---2.分区表,创建了主键索引,普通表也创建全局索引则

alter table tab_b add primary key(r_id);

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation update global indexes;

--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配

--3.分区表,创建了主键索引,普通表也创建主键索引则,且不包含索引交换

alter table tab_a exchange partition p_value1 with table tab_b /*including indexes*/ without validation /*update global indexes*/;

--成功---

--但是 insert into tab_a select  99199999,'test',1 from dual;

--ORA-01502: 索引 'SCOTT.SYS_C0012090' 或这类索引的分区处于不可用状态

---这时需要重建索引才能更新数据 ----

alter index SCOTT.SYS_C0012090 rebuild;

insert into tab_a select  99399999,'test',1 from dual;

---成功,,,

--4.分区表,创建了主键索引,普通表也创建主键索引则,且不包含索引交换,更新全局索引

truncate table tab_a;(/*清理分区不行*/)

insert into tab_a select  99199999,'test',1 from dual;

commit;

alter table tab_a exchange partition p_value1 with table tab_b /*including indexes*/ without validation update global indexes;

insert into tab_a select  99399999,'test',1 from dual;

---成功,,,

---但是更新普通表数据时,insert into tab_b select  99399999,'test',1 from dual 时,

--ORA-01502: 索引 'SCOTT.SYS_C0012090' 或这类索引的分区处于不可用状态

--------------------------

---5.在分区表的非分区表键上建立全局索引,普通表也建立全局索引

alter table tab_a drop primary key;

alter table tab_b drop primary key;

create index idx_a_r_id on tab_a(r_id) ;

create index idx_b_r_id on tab_b(r_id) ;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

-----ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配

---6.在分区表的非分区表键上建立全局索引,普通表不建立全局索引

drop index idx_b_r_id;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

---成功

-----7.在分区表的非分区键上建立本地索引,普通表不创建索引

drop index idx_a_r_id;

create index idx_a_r_id on tab_a(r_id) local;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配

-----8.在分区表的非分区键上建立本地索引,普通表创建索引

create index idx_b_r_id on tab_b(r_id) ;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

---成功

---9.在分区表的分区键上创建全局索引,普通表创建索引

drop index idx_a_r_id;

drop index idx_b_r_id;

create index idx_a_r_pat on tab_a(r_pat) ;

create index idx_b_r_pat on tab_b(r_pat) ;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配

---10.在分区表的分区键上创建全局索引,普通表不创建索引

drop index idx_a_r_pat;

drop index idx_b_r_pat;

create index idx_a_r_pat on tab_a(r_pat) ;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

---成功

-----11.在分区表的分区键上创建本地索引,普通表不创建索引

drop index idx_a_r_pat;

create index idx_a_r_pat on tab_a(r_pat) local;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

--ORA-14098: ALTER TABLE EXCHANGE PARTITION 中的表索引不匹配

----12.在分区表的分区键上创建本地索引,普通表创建索引

create index idx_b_r_pat on tab_b(r_pat) ;

alter table tab_a exchange partition p_value1 with table tab_b including indexes without validation;

---成功

---

---13.在分区表上的分区键和非分区键上创建全局索引,普通表上创建索引

drop index idx_a_r_id;

drop index idx_b_r_id;

create index idx_a_r_id on tab_a (r_id,r_pat);

create index idx_b_r_id on tab_b (r_id,r_pat);

alter table tab_a exchange partition p_value1 with table  tab_b including indexes without validation;

--报错

---14.在分区表上的分区键和非分区键上创建全局索引,普通表不创建索引

drop index idx_b_r_id;

alter table tab_a exchange partition p_value1 with table  tab_b including indexes without validation;

---成功

--15.在分区表上的分区键和非分区键上创建本地索引,普通表不创建索引

drop index idx_a_r_id;

create index idx_a_r_id on tab_a(r_id,r_pat) local;

alter table tab_a exchange partition p_value1 with table  tab_b including indexes without validation;

---报错

--16.在分区表上的分区键和非分区键上创建本地索引,普通表创建索引

create index idx_b_r_id on tab_b(r_id,r_pat) ;

alter table tab_a exchange partition p_value1 with table  tab_b including indexes without validation;

---成功

---17.在分区表上的分区键和非分区键上创建本地索引a,同时又在非分区键上创全局建索引b,普通表对应字段上都创建索引

drop index idx_a_r_id;

drop index idx_b_r_id;

create index idx_a_r_id on tab_a(r_id);

create index idx_b_r_id on tab_b(r_id);

create index idx_a_r_id_loc on tab_a(r_id,r_pat) local;

create index idx_b_r_id_loc on tab_b(r_id,r_pat) ;

alter table tab_a exchange partition p_value1 with table  tab_b including indexes without validation;

--报错

---18.在分区表上的分区键和非分区键上创建本地索引a,同时又在非分区键上创建全局索引b,

--在普通表对应的分区表上的本地索引a的字段上创建索引,同时分区表的全局索引对应的字段上不创建索引

drop index idx_a_r_id;

drop index idx_b_r_id;

drop index idx_a_r_id _loc;

drop index idx_b_r_id _loc;

create index idx_a_r_id on tab_a(r_id);

create index i idx_a_r_id_loc on tab_a (r_id,r_pat) local;

create index idx_b_r_id _loc on tab_b (r_id,r_pat) ;

alter table tab_a exchange partition p_value1 with table  tab_b including indexes without validation;

--成功

----以上创建普通表的索引时,都是跟分区表的字段相对应

oracle 入门笔记---分区表的分区交换的更多相关文章

  1. Oracle入门笔记 ——启动进阶

    1.2 进阶内容: 两个概念:SCN 和 检查点  1.SCN的定义:     system change member ,系统改变号,是数据库中非常重要的一个数据结构.     SCN 用以标示数据 ...

  2. Oracle入门笔记 ——启动

    参考教材<深入浅出Oracle> 兴趣 + 勤奋 + 坚持 + 方法 ≍ 成功 DBA生存之四大守则 1.备份重于一切: 2.三思而后行: 3.rm是危险的: 4.你来制定规范: 第一章: ...

  3. oracle 入门笔记--v$sql和v$sqlarea视图(转载)

    转载于作者:dbtan 原文链接:http://www.dbtan.com/2009/12/vsql-and-vsqlarea-view.html v$sql和v$sqlarea视图: 上文提到,v$ ...

  4. oracle分区交换技术

    交换分区的操作步骤如下: 1. 创建分区表t1,假设有2个分区,P1,P2.2. 创建基表t11存放P1规则的数据.3. 创建基表t12 存放P2规则的数据.4. 用基表t11和分区表T1的P1分区交 ...

  5. 【三思笔记】 全面学习Oracle分区表及分区索引

    [三思笔记]全面学习Oracle分区表及分区索引 2008-04-15 关于分区表和分区索引(About PartitionedTables and Indexes) 对于 10gR2 而言,基本上可 ...

  6. Oracle用分区表分区交换做历史数据迁移

    一. 说明: OLTP库中有些表数据量大,且每月有持续的大量数据添加.因为历史数据在此库中不再做訪问,而是在另1个OLAP库中做分析.所以会对历史数据迁移至OLAP库中.对这样的历史数据迁移的操作.较 ...

  7. 深入学习Oracle分区表及分区索引

    关于分区表和分区索引(About Partitioned Tables and Indexes)对于10gR2而言,基本上可以分成几类: •       Range(范围)分区 •       Has ...

  8. oracle 分区表和分区索引

    很复杂的样子,自己都没有看完,以备后用 http://hi.baidu.com/jsshm/item/cbfed8491d3863ee1e19bc3e ORACLE分区表.分区索引ORACLE对于分区 ...

  9. ORACLE分区表、分区索引详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt160 ORACLE分区表.分区索引ORACLE对于分区表方式其实就是将表分段 ...

随机推荐

  1. (6)文本挖掘(三)——文本特征TFIDF权重计算及文本向量空间VSM表示

    建立文本数据数学描写叙述的过程分为三个步骤:文本预处理.建立向量空间模型和优化文本向量. 文本预处理主要採用分词.停用词过滤等技术将原始的文本字符串转化为词条串或者特点的符号串.文本预处理之后,每个文 ...

  2. Android 实现形态各异的双向側滑菜单 自己定义控件来袭

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/39670935.本文出自:[张鸿洋的博客] 1.概述 关于自己定义控件側滑已经写了 ...

  3. Java总结之网络

    [网络基础概念] 什么是计算机网络: 把分布在不同地理区域的计算机与专门的外部设备用通信线路互连成一个规模大.功能强的网络系统,从而使众多的计算机能够方便的互相传递信息,共享硬件.软件.数据信息等资源 ...

  4. Wicket实战(一)概述

    今天给大家介绍一个很好的东西.一个被称作Java平台上的ASP.NET--Wicket. 什么是Wicket 什么是Wicket,假设你用谷歌或其它搜索引擎搜索一番之后,就会发现wicket是Java ...

  5. 2016/1/12 第一题 输出 i 出现次数 第二题 用for循环和if条件句去除字符串中空格 第三题不用endwith 实现尾端字符查询

    import java.util.Scanner; public class Number { private static Object i; /* *第一题 mingrikejijavabu中字符 ...

  6. 蓝桥 PREV-30 历届试题 波动数列 【动态规划】

      历届试题 波动数列   时间限制:1.0s   内存限制:256.0MB      问题描述 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个数列中后一项总是比前一项增加2或者减少3. ...

  7. Swing手动进行最大化最小化

    首先jdk的setExtendedState是有bug的,需要先重载JFrame的setExtendedState方法 /** * Fix the bug "jframe undecorat ...

  8. virtual (C# Reference)

    https://msdn.microsoft.com/en-us/library/9fkccyh4.aspx The virtual keyword is used to modify a metho ...

  9. URAL 1057 数位dp

    题目传送门http://acm.timus.ru/problem.aspx?space=1&num=1057 最近在学习数位dp,具体姿势可以参照这篇论文:http://wenku.baidu ...

  10. 【T^T】【周赛】第一周周赛——欢迎16级的新同学

    借光光,YZC的福气(今天拿到Rank1),本来还可以更好的,前面吃M去了,ABC都很晚切,而且异常兴奋,结果WA了好多发,但还是由于水题看题不清,分析不清导致的 A Home W的数学 Descri ...