Oracle建立普通表轉換為分割槽表

2021-06-20 04:36:48 字數 1551 閱讀 1535

在oracle中要把表名重名名為字串加上日期格式

使用下面命令:  

begin

execute immediate 'alter table old_table_name rename to new_table_name'||to_char(sysdate, 'yyyymmdd');

end;

commit;

利用交換表把普通表轉換為分割槽表:

create table table_new

( request_time date not null,

)partition by range(request_time)

interval (numtodsinterval(1,'day'))

( partition p_day_1 values less than (to_date('2014-1-15','yyyy-mm-dd'))

);

這樣建立乙個新錶。alter table table_new  exchange partition p_day_1 with table  table_old,實現資料的交換。。交換後原來表中的資料將會分到

建立的第乙個分割槽中。。

建立分割槽完成後,發現表的查詢比原來慢了很多。。現在考慮建立分割槽索引來加快分割槽查詢速度。。

create index idx_ard_s_rtm_par on table_new(request_time)  

global partition by range(request_time)(

partition p_day_1 values less than (to_date('2014-1-15','yyyy-mm-dd')),

partition idx_p3 values less than (maxvalue)

);

建立測試資料: 

begin

for i in 1..12 loop

insert into table_new values(

trunc(to_date('2014-01-15','yyyy-mm-dd')+i));

end loop;

commit;

end;

檢視分割槽情況: 

select table_name,partition_name from user_tab_partitions where table_name='table_new'; //注意要大寫

檢視分割槽資料:

select * from table_new partition(p_day_1);
測試完畢可以重新命名:

rename table_name  to table_old;
rename table_new  to table_name;

普通表轉換為分割槽表 oracle9i

以下為在乙個專案中寫的解決 資料庫為oracle9i,在執行下面的 時,系統需要停掉 其他資訊mt表 create table t other mt new partition by list send request status partition part no values 0 partit...

普通LIST列表轉換為Tree

public class xmgltaskdto 重新將list轉為tree 方式1 迴圈 listnodelist new arraylist for xmgltaskdto node1 taskdtolist if mark 重新將list轉為tree 方式2 遞迴 listnodelist n...

oracle列轉換為行

首先介紹行轉換為列,oracle行轉換為列是比較常見,網上常見的例子如下 grades表 student subject grade student1 語文 80 student1 數學 70 student1 英語 60 student2 語文 90 student2 數學 80 student2...