DBMS_REDEFINITION(線上重定義一個重要bug)
線上重定義後會發現列not null沒有copy過來,
執行sql alter table modify column not null
報如下錯誤
ORA-01442: column to be modified to NOT NULL is already NOT NULL透過sql查詢發現
select constraint_name,constraint_type,status,validated
from user_constraints
where constraint_name in (select constraint_name from user_cons_columns where table_name='TEST' and column_name='TEST');
列都是NOT VALIDATED 狀態
查詢MOS發現時一個bug mos 詳細資訊如下:ID 1089860.1
APPLIES TO:
Oracle Server - Enterprise Edition - Version 10.2.0.1 and laterInformation in this document applies to any platform.
Reviewed for relevance 24 April 2012
SYMPTOMS
After redefining a table using DBMS_REDEFINITION it is found that a describe of the table no longer shows the NOT NULL constraints
CAUSE
The cause of this condition is two fold
1) The constraint really was not copied ... due to COMPATIBLE not being 10.2 or higher
2) The constraint was copied ... but appears to not have been ... (ie a describe shows a
These are discussed in the INTERNAL ONLY bug
ET10.2OREDEF: NULLABLE COL OF *_TAB_COLUMNS TABLE NOT UPDATED AFTER ONLINE REDEF
"In order to copy Not Null constraints, COMPATIBLE must be set to 10.2 or higher. "
"Not null/Primary key constraints are copied in NOVALIDATE mode in order to speed up the redefinition process."
SOLUTION
1) If COMPATIBLE < 10.2 then NOT NULL constraints must be manually copied or the redefinition restarted with compatible set to 10.2 or higher
2) If COMPATIBLE => 10.2 the constraints will be copied ... but will be in NOVALIDATE mode
The not null constraint CAN be reenabled for VALIDATE using the ALTER TABLE ... ENABLE VALIDATE CONSTRAINT ... command
CASE STUDY
create user test identified by test;
grant dba to test;
alter user test default tablespace users;
connect test/test;
SHOW PARAMETER COMPATIBLE
-- NAME TYPE VALUE
-- ------------------------------------ ----------- ------------------------------
-- compatible string 11.2.0.0.0
-- CREATE THE TABLE TO BE REDEFINED
CREATE TABLE ORIGINAL (COL1 VARCHAR2(10) NOT NULL);
-- Table created.
-- CREATE THE INTERIM TABLE FOR THE REDEFINITION
CREATE TABLE INTERIM (COL1 VARCHAR2(20));
-- Table created.
-- DESCRIBE THE TWO TABLES JUST CREATED
DESC ORIGINAL
-- ---------------- -------- ----------------------------
-- COL1 NOT NULL VARCHAR2(10)
DESC INTERIM
-- ---------------- -------- ----------------------------
-- COL1 VARCHAR2(20)
-- PROVE THAT THE REDEFINITION CAN WORK
exec dbms_redefinition.can_redef_table('TEST','ORIGINAL', dbms_redefinition.cons_use_rowid);
-- PL/SQL procedure successfully completed.
-- START THE REDEFINITION
exec dbms_redefinition.start_redef_table('TEST','ORIGINAL','INTERIM','COL1 COL1',dbms_redefinition.cons_use_rowid);
-- PL/SQL procedure successfully completed.
-- COPY THE CONSTRIANTS FROM THE ORIGINAL TABLE TO THE INTERIM TABLE
SET SERVEROUTPUT ON
DECLARE
error_count pls_integer := 0;
BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('TEST',
'ORIGINAL',
'INTERIM',
dbms_redefinition.cons_orig_params ,
TRUE,
TRUE,
TRUE,
FALSE,
error_count);
DBMS_OUTPUT.PUT_LINE('errors := ' || TO_CHAR(error_count));
END;
/
-- PL/SQL procedure successfully completed.
-- FINISH THE REDEFINITION (THIS IS WHERE THE ROWS GET COPIED)
exec dbms_redefinition.finish_redef_table('TEST','ORIGINAL','INTERIM');
-- PL/SQL procedure successfully completed.
--LOOK AT THE DESCRIPTION OF THE NEWLY REDFINED TABLE
DESC ORIGINAL
-- Name Null? Type
-- ----------------------------------------- -------- ----------------------------
-- COL1 VARCHAR2(20)
-- ---------------- -------- ----------------------------
-- COL1 VARCHAR2(20)
-- NOTICE THAT OUR 'Null?' column no longer says 'NOT NULL'
-- this would imply that our constraint is gone
-- PROVE THAT THE CONSTRAINT STILL EXISTS
SELECT CONSTRAINT_NAME, VALIDATED FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'ORIGINAL';
-- ------------------------------ -------------
-- SYS_C0011548 NOT VALIDATED
-- THE CONSTRAINT EXISTS BUT IS 'NOT VALIDATED'
-- ALTER THE TABLE SO THAT THE NOT NULL CONSTRAINT IS NOW VALIDATED
ALTER TABLE ORIGINAL ENABLE VALIDATE CONSTRAINT SYS_C0011548;
-- Table altered.
-- REEXAMINE THE TABLE
DESC ORIGINAL
-- ---------------- -------- ----------------------------
-- COL1 NOT NULL VARCHAR2(20)
SELECT CONSTRAINT_NAME, VALIDATED FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'ORIGINAL';
-- CONSTRAINT_NAME VALIDATED
-- ------------------------------ -------------
-- SYS_C0011548 VALIDATED
-- ------------------------------ -------------
-- SYS_C0011548 VALIDATED
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-1184339/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- dbms_redefinition線上重定義表
- Oracle線上重定義之DBMS_REDEFINITIONOracle
- 利用DBMS_REDEFINITION線上重定義表
- 線上重定義表(Redefine Tables Online) - dbms_redefinition
- 分割槽表和dbms_redefinition包線上重定義表
- 使用DBMS_REDEFINITION線上重定義表普通表為分割槽表
- 使用DBMS_REDEFINITION包執行線上重定義表(ONLINE TABLE REDEFINITION)
- Oracle表的線上重定義(一)Oracle
- 【REDEFINITION】使用線上重定義dbms_redefinition完成主鍵列型別的調整型別
- oracle 線上重定義Oracle
- Oracle線上重定義Oracle
- Online Redefinition線上重定義(一)
- dbms_redefinition利用線上重定義把普通錶轉化為分割槽表的一些測試
- oracle 表線上重定義Oracle
- oracle表線上重定義Oracle
- 【Oracle】線上重定義表Oracle
- Oracle的線上重定義(轉)Oracle
- oracle線上重定義表步驟Oracle
- Online Redefinition線上重定義(三)--多表關聯重定義案例
- 10g線上重定義新特性——對單獨的分割槽進行線上重定義
- 物化檢視prebuilt和線上重定義UI
- Oracle中重建表的線上重定義Oracle
- 資料庫表的線上重定義資料庫
- 線上重定義表ORACLE 11GOracle
- 【redefinition】線上重定義概覽與使用
- Oracle Online Redefinition線上重定義(上)Oracle
- Oracle Online Redefinition線上重定義(中)Oracle
- Oracle Online Redefinition線上重定義(下)Oracle
- 【TABLE】oracle表線上重定義注意事項Oracle
- oracle實驗記錄 (線上重定義表)Oracle
- 在oracle 9i下線上重定義表Oracle
- 普通錶轉換分割槽表-線上重定義
- 線上重定義引起的資料庫掛起資料庫
- Oracle 9i中表的線上重定義(轉)Oracle
- ORACLE 線上重新定義表分割槽表重定義為普通表。Oracle
- 線上重定義 ?普通錶轉換成分割槽表
- OCM實驗-使用線上重定義方式遷移表
- 海量資料處理_表分割槽(線上重定義)