Oracle table is redefined as a partition table online (example)

Source: Internet
Author: User

Oracle TABLE is online redefined AS a partitioned TABLE (example) SQL> CREATE TABLE TT AS SELECT * FROM DBA_OBJECTS WHERE OBJECT_TYPE IN ('table', 'index', 'function '); -- the original table has been created. Www.2cto.com SQL> EXEC pipeline ('admin', 'TT', DBMS_REDEFINITION.CONS_USE_PK); -- checks whether you can redefine BEGIN pipeline ('admin', 'TT', DBMS_REDEFINITION.CONS_USE_PK); END; * row 1st error: ORA-12089: The table "ADMIN" without a primary key cannot be redefined online ". "TT" ORA-06512: In "SYS. DBMS_REDEFINITION ", line 137ORA-06512: In" SYS. DBMS_REDEFINITION ", line 1478ORA-06512: In line 1 SQL> ALTER TABLE TT ADD PRIMARY KEY (OBJECT_ID); -- the created primary KEY index table has been changed. SQL> EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE ('admin', 'TT', DBMS_REDEFINITION.CONS_USE_PK); the PL/SQL process has been completed successfully. Www.2cto.com SQL> CREATE TABLE MID_TT -- CREATE intermediate TABLE 2 (3 OWNER VARCHAR2 (30), 4 OBJECT_NAME VARCHAR2 (128), 5 SUBOBJECT_NAME VARCHAR2 (30), 6 OBJECT_ID NUMBER NOT NULL, 7 DATA_OBJECT_ID NUMBER, 8 OBJECT_TYPE VARCHAR2 (19), 9 created date, 10 LAST_DDL_TIME DATE, 11 TIMESTAMP VARCHAR2 (19), 12 STATUS VARCHAR2 (7), 13 TEMPORARY VARCHAR2 (1 ), 14 GENERATED VARCHAR2 (1), 15 SECONDARY VARCHAR2 (1) 16) tablespace test 17 Partition by list (OBJECT_TYPE) (18 partition tab values ('table'), 19 partition idx values ('index'), 20 partition func values ('function') 21 ); the table has been created. SQL> EXEC DBMS_REDEFINITION.START_REDEF_TABLE ('admin', 'TT', 'mid _ tt'); -- the re-definition PL/SQL process of the initialization table has been completed successfully. Www.2cto.com SQL> EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE ('admin', 'TT', 'mid _ tt'); -- the table redefinition PL/SQL process has been completed successfully. SQL> SELECT SEGMENT_NAME, PARTITION_NAME FROM DBA_SEGMENTS WHERE SEGMENT_NAME IN ('TT', 'mid _ tt') AND OWNER = 'admin '; -- the structure of the original table and the structure interchange of the intermediate table SEGMENT_NAME PARTITION_NAME-------------------------------------------------------------------MID_TTTT tabtt idxtt func SQL> SELECT TABLE_NAME, INDEX_NAME FROM DBA_INDEXES WHERE TABLE_NAME IN ('TT', 'mid _ tt ') and owner = 'admin'; -- the primary key index of the original table is also created in the middle table TABLE_NAME INDEX_NAME ---------------------------- -------------------------- MID_TT SYS_C007791

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.