How To Change the Partition Column Of A Partitioned Table Using DBMS_Redefinition [ID 846405.1]

How To Change the Partition Column Of A Partitioned Table Using DBMS_Redefinition [ID 846405.1]


 

Modified 22-OCT-2009     Type HOWTO     Status PUBLISHED

 

In this Document
  Goal
  Solution
  References


Applies to:

Oracle Server - Enterprise Edition - Version: 10.2.0.4 to 11.2.0.2.0
Information in this document applies to any platform.

Goal

The purpose of this document is to provide step by step instructions on how to convert the partitioned column of an existing partitioned table to have a completely different partitioned column using dbms_redefinition package.

Solution

1) Create partitioned table (This is the table that needs to be redefined) with the name SALES.  We plan to repartition this table to use the MONTH_NO as the partitioning column.

Note:  The table already has a PK on this defined in the Create statement.

CREATE TABLE sales ( 
acct_no NUMBER(5), 
acct_name CHAR(30), 
amount_of_sale NUMBER(6), 
week_no INTEGER, 
month_no integer, 
sale_details VARCHAR2(1000), 
PRIMARY KEY (acct_no, acct_name, week_no)) 
PARTITION BY LIST (week_no) ( 
PARTITION part1234 VALUES (1, 2, 3, 4) tablespace users, 
PARTITION part5678 VALUES (5, 6, 7, 8) tablespace users, 
PARTITION partdefault VALUES (DEFAULT) tablespace users); 

insert into sales values (1,'acc 1',1,52,12,'sales details 1'); 
insert into sales values (2,'acc 2',2,51,12,'sales details 2'); 
insert into sales values (3,'acc 3',3,50,12,'sales details 3'); 
insert into sales values (4,'acc 4',4,1,1,'sales details 4'); 
insert into sales values (5,'acc 5',5,2,1,'sales details 5'); 
commit;

2) Gather statistics on the table:

EXEC DBMS_STATS.gather_table_stats('RK_MVIEW', 'SALES', cascade => TRUE);

3) Create a Partitioned Interim Table:

CREATE TABLE interim_sales ( 
     acct_no NUMBER(5), 
     acct_name CHAR(30), 
     amount_of_sale NUMBER(6),  
     week_no INTEGER, 
     month_no integer, 
     sale_details VARCHAR2(1000), 
     PRIMARY KEY (acct_no, acct_name, month_no))  
     PARTITION BY LIST (month_no) ( 
     PARTITION int_part1 VALUES (1) tablespace users, 
     PARTITION int_part12 VALUES (12) tablespace users, 
     PARTITION int_partdefault VALUES (DEFAULT) tablespace users);

4) Start the Redefinition Process: 

a) Check the redefinition is possible using the following command:

EXEC Dbms_Redefinition.can_redef_table('RK_MVIEW', 'SALES');

b)If no errors are reported, start the redefintion using the following command:

BEGIN  
DBMS_REDEFINITION.start_redef_table(  
uname => 'RK_MVIEW',   
orig_table => 'SALES',  
int_table => 'INTERIM_SALES');  
END;  

c) Optionally synchronize new table with interim name before index creation:

BEGIN  
dbms_redefinition.sync_interim_table(  
uname => 'RK_MVIEW',   
orig_table => 'SALES',  
int_table => 'INTERIM_SALES');   
END;  

d) Gather statistics on the new table:

EXEC DBMS_STATS.gather_table_stats('RK_MVIEW', 'INTERIM_SALES', cascade => TRUE); 

e) Complete the Redefintion Process:

BEGIN  
dbms_redefinition.finish_redef_table(  
uname => 'RK_MVIEW',   
orig_table => 'SALES',  
int_table => 'INTERIM_SALES');  
END;  

At this point the interim table has become the "real" table and their names have been switched in the name dictionary. 

f) Remove original table which now has the name of the interim table:

DROP TABLE INTERIM_SALES;

g) Check whether partitioning is successful or not:

SELECT partition_name 
FROM user_tab_partitions 
WHERE table_name = 'SALES';                                                                                                      

PARTITION_NAME 
------------------ 
INT_PART1 
INT_PART12 
INT_PARTDEFAULT

 

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
insert overwrite table discountdw.dwd_sd_adds_order_bill_inc partition(dt = '2023-06-06') select t1.order_bill_id, t1.counterfoil_no, t1.acceptor, date_format(to_utc_timestamp(cast(t1.expiry_date as bigint) ,'GMT-8'),'YYYY-MM-dd'), t2.company_id, t1.cert_no, t1.company_name, t1.third_order_id, t1.counterfoil_amt/10000, t1.transaction_amt/10000, t1.rate, '3bp' as service_tariffing, ((DATEDIFF(to_utc_timestamp(t1.expiry_date ,'GMT-8'),to_utc_timestamp(t1.transaction_date ,'GMT-8') ) + adjust_days)* 0.0003 *(counterfoil_amt))/ 360 as service_fee, 360 as total_days, DATEDIFF(to_utc_timestamp(t1.expiry_date ,'GMT-8'),to_utc_timestamp(t1.transaction_date ,'GMT-8') ) + adjust_days as modulation_date, t3.channel_type, t3.bank_name, date_format(to_utc_timestamp(cast(t1.transaction_date as bigint) ,'GMT-8'),'YYYY-MM-dd'), t1.order_status_code, t1.order_status_msg, t4.fee_amt, t4.status, t1.tenant_id, t5.revenue, to_utc_timestamp(cast(t1.create_date as bigint) ,'GMT-8'), to_utc_timestamp(cast(t1.update_date as bigint) ,'GMT-8') from (select * from discountdw.ods_adds_order_bill_inc where dt ='2023-06-06' and channel_id=101110004 )t1 left join (select * from mecdw.ods_company_full where platform_id='sdpjw')t2 on t1.cert_no=t2.cert_no and t1.tenant_id=t2.tenant_id left join discountdw.dim_adds_product_full t3 on t1.partner_id=t3.partner_id and t1.product_id=t3.product_id left join (select * from mecdw.dwd_sc_fee_record_full where dt='2023-06-06' and biz_type=2 ) t4 on t1.order_bill_id=t4.third_id left join (select * from discountdw.ods_sd_order_ext_inc where dt='2023-06-06') t5 on t1.order_bill_id=t5.order_bill_id left join sdpjwdw.dim_holiday_info_full t6 on date_format(to_utc_timestamp(t1.expiry_date ,'GMT-8'),'YYYY-MM-dd') = t6.civic_holiday ;
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值