--操做的用戶須要有如下的權限
GRANT CONNECT, RESOURCE TO CMIGDW;
GRANT EXECUTE ON DBMS_REDEFINITION TO CMIGDW;
GRANT ALTER ANY TABLE TO CMIGDW;
GRANT DROP ANY TABLE TO CMIGDW;
GRANT LOCK ANY TABLE TO CMIGDW;
GRANT CREATE ANY TABLE TO CMIGDW;
GRANT SELECT ANY TABLE TO CMIGDW;
GRANT CREATE ANY TRIGGER TO CMIGDW;
GRANT CREATE ANY INDEX TO CMIGDW;
--須要分區的表
select * from CMIGDW.TEST_DATE_DIM;
--表結構
create table TEST_DATE_DIM
(
date_id NUMBER,
year_ NUMBER,
half_year VARCHAR2(20),
season_id VARCHAR2(20),
season VARCHAR2(20),
month_ NUMBER,
week NUMBER
);
--建立一個與TEST_DATE_DIM 表字段相同,可是分區的表
create table TEST_DATE_DIM2
(
date_id NUMBER,
year_ NUMBER,
half_year VARCHAR2(20),
season_id VARCHAR2(20),
season VARCHAR2(20),
month_ NUMBER,
week NUMBER
)
PARTITION BY list (month_)
(
PARTITION P1 values (201501),
PARTITION P2 values (201502),
PARTITION P3 values (default)
);
--開始在線重定義
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
Connected as CMIGDW@CMIG_TEST
SQL> EXEC dbms_redefinition.start_redef_table('CMIGDW', 'TEST_DATE_DIM', 'TEST_DATE_DIM2');
begin dbms_redefinition.start_redef_table('CMIGDW', 'TEST_DATE_DIM', 'TEST_DATE_DIM2'); end;
ORA-12089: 不能聯機從新定義無主鍵的表 "CMIGDW"."TEST_DATE_DIM"
ORA-06512: 在 "SYS.DBMS_REDEFINITION", line 56
ORA-06512: 在 "SYS.DBMS_REDEFINITION", line 1490
ORA-06512: 在 line 1
須要有主鍵
--開始執行在線重定義
SQL> EXEC dbms_redefinition.start_redef_table('CMIGDW', 'TEST_DATE_DIM', 'TEST_DATE_DIM2');
PL/SQL procedure successfully completed
SQL>
SQL> DECLARE
2 error_count pls_integer := 0;
3 BEGIN
4 dbms_redefinition.copy_table_dependents('CMIGDW', 'TEST_DATE_DIM', 'TEST_DATE_DIM2',
5 0, true, false, true, false,
6 error_count);
7
8 dbms_output.put_line('errors := ' || to_char(error_count));
9 END;
10 /
PL/SQL procedure successfully completed
--結束在線重定義
SQL> EXEC dbms_redefinition.finish_redef_table('CMIGDW', 'TEST_DATE_DIM', 'TEST_DATE_DIM2');
PL/SQL procedure successfully completed
SQL> select * from TEST_DATE_DIM PARTITION (p1);
SQL> select * from TEST_DATE_DIM2;
-- 刪除中間表
DROP TABLE TEST_DATE_DIM2;