創(chuàng)建表test_part_1 默認(rèn)為users表空間:
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、雅安服務(wù)器托管、營(yíng)銷軟件、網(wǎng)站建設(shè)、南雄網(wǎng)站維護(hù)、網(wǎng)站推廣。
create table test_part_1(a number, b number)
partition by range(a)
(
partition p1 values less than (10),
partition p2 values less than (20),
partition p3 values less than (30),
partition p4 values less than (40)
);
創(chuàng)建test_part_1 本地索引
create index idx_id on test_part_1(a) local tablespace TS_KSZIP_BASE;
--插入記錄
insert into test_part_1 values(1,2);
insert into test_part_1 values(11,2);
insert into test_part_1 values(21,2);
insert into test_part_1 values(31,2);
commit;
--查看記錄
select rowid from test_part_1 where a=1;--AAAlz4AAEAAFTUEAAA 查詢1
--創(chuàng)建中間表
create table test_part_3(a number, b number);
create index idx_id3 on test_part_3(a);--默認(rèn)表空間users
--test_part_1 與中間表交換
alter table test_part_1 exchange partition p1 with table test_part_3 including indexes with validation; --目標(biāo)表有數(shù)據(jù)不能交換,交換只能是分區(qū)和非分區(qū)表交換
--驗(yàn)證
select * from dba_ind_partitions where index_name=upper('idx_id');--p1的表空間變成了users,并且狀態(tài)為usable,不用rebuild
select * from dba_indexes where index_name=upper('idx_id3');--表空間變成了TS_KSZIP_BASE.
select rowid from test_part_3;--AAAlz4AAEAAFTUEAAA 跟查詢1對(duì)比可見(jiàn) 只是改了數(shù)據(jù)字典
--創(chuàng)建 目標(biāo)分區(qū)表test_part_2
create table test_part_2(a number, b number)
partition by range(a)
(
partition p1 values less than (10),
partition p2 values less than (20),
partition p3 values less than (30),
partition p4 values less than (40),
partition p5 values less than (50)
);
create index idx_id2 on test_part_2(a) local tablespace TS_KSZIP_BASE;
alter table test_part_2 exchange partition p1 with table test_part_3 including indexes with validation; --目標(biāo)表有數(shù)據(jù)不能交換,交換只能是分區(qū)非分區(qū)交換
select * from dba_ind_partitions where index_name=upper('idx_id2');--索引p1可用,表空間依然是TS_KSZIP_BASE(因?yàn)榇藭r(shí) idx_id3表空間為TS_KSZIP_BASE)
select * from dba_indexes where index_name=upper('idx_id3');--表空間為TS_KSZIP_BASE,狀態(tài)也是usable