oracle 交換分割槽歷史資料歸檔
設定時間格式
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
//建立表 並分割槽
create table acc_item_cur
(acc_item number,
acc_item_desc varchar2(20),
acc_date date,
area_code varchar2(6)
)
partition by range (acc_date)
subpartition by list (area_code)
(partition d1 values less than (TO_DATE('2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d1_con1 values('ASIA','AUST'),
subpartition d1_con2 values('AMER'),
subpartition d1_con3 values('AFRICA'),
subpartition d1_con4 values('EUROPE')),
partition d2 values less than (TO_DATE('2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d2_con1 values('ASIA','AUST'),
subpartition d2_con2 values('AMER'),
subpartition d2_con3 values('AFRICA'),
subpartition d2_con4 values('EUROPE')),
partition d3 values less than (TO_DATE('2012-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d3_con1 values('ASIA','AUST'),
subpartition d3_con2 values('AMER'),
subpartition d3_con3 values('AFRICA'),
subpartition d3_con4 values('EUROPE'))
);
create table acc_item_cur
(acc_item number,
acc_item_desc varchar2(20),
acc_date date,
area_code varchar2(6)
)
partition by range (acc_date)
subpartition by list (area_code)
(partition d1 values less than (TO_DATE('2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d1_con1 values('ASIA','AUST'),
subpartition d1_con2 values('AMER'),
subpartition d1_con3 values('AFRICA'),
subpartition d1_con4 values('EUROPE')),
partition d2 values less than (TO_DATE('2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d2_con1 values('ASIA','AUST'),
subpartition d2_con2 values('AMER'),
subpartition d2_con3 values('AFRICA'),
subpartition d2_con4 values('EUROPE')),
partition d3 values less than (TO_DATE('2012-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d3_con1 values('ASIA','AUST'),
subpartition d3_con2 values('AMER'),
subpartition d3_con3 values('AFRICA'),
subpartition d3_con4 values('EUROPE'))
);
新增本地索引,並將其設定為主鍵。
SQL> create unique index pk_acc_item_cur on acc_item_cur(acc_item,acc_date,area_code) local;
SQL> create unique index pk_acc_item_cur on acc_item_cur(acc_item,acc_date,area_code) local;
Index created.
SQL> alter table acc_item_cur add primary key (acc_item,acc_date,area_code) using index
pk_acc_item_cur;
Table altered.
SQL> create sequence seq_acc_item cache 10000 noorder;
Sequence created.
SQL> declare
vdate date;
begin
vdate:=to_date('2012-01-01','yyyy-mm-dd');
for i in 1.. 4000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'ASIA');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AMER');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AFRICA');
end loop
commit;
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AFRICA');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'EUROPE');
end loop
commit;
end; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'EUROPE');
end loop
commit;
end; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20 21 22 23
24 /
24 /
PL/SQL procedure successfully completed.
SQL> declare
vdate date;
begin
vdate:=to_date('2012-02-05','yyyy-mm-dd');
for i in 1.. 4000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'ASIA');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AMER');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AFRICA');
end loop
commit;
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AFRICA');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'EUROPE');
end loop
commit;
end; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'EUROPE');
end loop
commit;
end; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20 21 22 23
24 /
24 /
PL/SQL procedure successfully completed.
SQL> declare
vdate date;
begin
vdate:=to_date('2012-03-05','yyyy-mm-dd');
for i in 1.. 4000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'ASIA');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AMER');
end loop
commit;
vdate date;
begin
vdate:=to_date('2012-03-05','yyyy-mm-dd');
for i in 1.. 4000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'ASIA');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AMER');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AFRICA');
end loop
commit;
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'AFRICA');
end loop
commit;
for i in 1.. 5000 loop
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'EUROPE');
end loop
commit;
end; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
insert into acc_item_cur values(seq_acc_item.nextval,to_char(i),vdate,'EUROPE');
end loop
commit;
end; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20 21 22 23
24 /
24 /
PL/SQL procedure successfully completed.
建立中間表
SQL> create table acc_item_ex
2 (acc_item number,
3 acc_item_desc varchar2(20),
4 acc_date date,
5 area_code varchar2(6)
6 )
7 partition by list (area_code)
8 (partition d1_con1 values('ASIA','AUST'),
9 partition d1_con2 values('AMER'),
10 partition d1_con3 values('AFRICA'),
11 partition d1_con4 values('EUROPE'));
2 (acc_item number,
3 acc_item_desc varchar2(20),
4 acc_date date,
5 area_code varchar2(6)
6 )
7 partition by list (area_code)
8 (partition d1_con1 values('ASIA','AUST'),
9 partition d1_con2 values('AMER'),
10 partition d1_con3 values('AFRICA'),
11 partition d1_con4 values('EUROPE'));
Table created.
//建立索引
create unique index pk_acc_item_ex on acc_item_ex(acc_item,acc_date,area_code) local;
alter table acc_item_ex add primary key (acc_item,acc_date,area_code) using index pk_acc_item_ex;
alter table acc_item_ex add primary key (acc_item,acc_date,area_code) using index pk_acc_item_ex;
建立歷史表
SQL> create table acc_item_his
(acc_item number,
acc_item_desc varchar2(20),
acc_date date,
area_code varchar2(6)
)
partition by range (acc_date)
subpartition by list (area_code)
(partition d1 values less than (TO_DATE('2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d1_con1 values('ASIA','AUST'),
subpartition d1_con2 values('AMER'),
subpartition d1_con3 values('AFRICA'),
subpartition d1_con4 values('EUROPE')),
partition d2 values less than (TO_DATE('2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d2_con1 values('ASIA','AUST'),
subpartition d2_con2 values('AMER'),
subpartition d2_con3 values('AFRICA'),
subpartition d2_con4 values('EUROPE')),
partition d3 values less than (TO_DATE('2012-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS','NLS_CALENDAR=GREGORIAN'))
(subpartition d3_con1 values('ASIA','AUST'),
subpartition d3_con2 values('AMER'),
subpartition d3_con3 values('AFRICA'),
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 subpartition d3_con4 values('EUROPE'))
); 21 22 23 24
/
Table created.
SQL> create unique index pk_acc_item_cur on acc_item_his(acc_item,acc_date,area_code) local;
SQL> create unique index pk_acc_item_cur on acc_item_his(acc_item,acc_date,area_code) local;
Index created.
SQL> alter table acc_item_his add primary key (acc_item,acc_date,area_code) using index
pk_acc_item_his;
交換分割槽
SQL> alter table acc_item_cur exchange partition d1 with table acc_item_ex including index ;
SQL> alter table acc_item_cur exchange partition d1 with table acc_item_ex including index ;
執行失敗,去除including index 執行OK
alter table acc_item_cur exchange partition d1 with table acc_item_ex OK
SQL> alter table acc_item_his exchange partition d1 with table acc_item_ex including index without validation ;
SQL> alter table acc_item_his exchange partition d1 with table acc_item_ex including index without validation ;
執行失敗 ,去除including index 執行OK
alter table acc_item_his exchange partition d1 with table acc_item_ex without validation ;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15187685/viewspace-752897/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle分割槽交換(exchange)技術Oracle
- linux交換分割槽Linux
- Oracle資料庫分割槽表SPLIT操作導致歸檔瘋漲Oracle資料庫
- unbuntu新增交換分割槽
- linux交換分割槽調整Linux
- Ubuntu 啟用交換分割槽Ubuntu
- MySQL使用pt-archiver歸檔歷史資料MySqlHive
- oracle交換分割槽所引起的索引失效問題探究測試Oracle索引
- 交換分割槽時報錯:ORA-14098
- 雲端計算:交換分割槽管理 Swap
- Oracle資料庫歸檔模式的切換ELOracle資料庫模式
- ORACLE刪除-表分割槽和資料Oracle
- Linux下swap(交換分割槽)的增刪改Linux
- Seven 儲存結構與磁碟劃分 主分割槽交換分割槽的作用!
- oracle 更改分割槽表資料 ora-14402Oracle
- [20190503]12C R2 分割槽交換.txt
- oracle分割槽表和分割槽表exchangeOracle
- Oracle 12.2之後ALTER TABLE .. MODIFY轉換非分割槽表為分割槽表Oracle
- Oracle查詢Interval partition分割槽表內資料Oracle
- oracle分割槽表和非分割槽表exchangeOracle
- [oracle] expdp 匯出分割槽表的分割槽Oracle
- mysql分割槽表佔用大量容量處理(最佳化)及歸檔分割槽表MySql
- 非分割槽錶轉換成分割槽表
- MySql資料分割槽操作之新增分割槽操作MySql
- 淺析資料中心交換機晶片,中國自主可控國產化交換機已是歷史必然晶片
- Oracle分割槽表基礎運維-07增加分割槽(2 HASH分割槽)Oracle運維
- Oracle 資料庫 10g中的分割槽功能(轉)Oracle資料庫
- Linux交換分割槽相關都有哪些命令?Linux運維基礎Linux運維
- Oracle分割槽表基礎運維-07增加分割槽(1範圍分割槽)Oracle運維
- ORACLE分割槽表梳理系列Oracle
- oracle 分割槽表move和包含分割槽表的lob moveOracle
- Oracle分割槽表基礎運維-09刪除分割槽Oracle運維
- Oracle分割槽表基礎運維-05組合分割槽Oracle運維
- Oracle分割槽表基礎運維-02範圍分割槽Oracle運維
- Oracle分割槽表基礎運維-03HASH分割槽Oracle運維
- Oracle分割槽表基礎運維-07增加分割槽(3列表分割槽)Oracle運維
- Oracle12c:建立主分割槽、子分割槽,實現自動分割槽插入效果Oracle
- 調整分割槽後分割槽不見的資料找到方法
- 小白自制Linux開發板 五. Debian檔案系統製作,以及WIFI配置、交換分割槽配置LinuxWiFi