Oracle online redefinition of modifying table structure

Source: Internet
Author: User


Online redefinition and modification of table structure: database version: SQL> select * from v $ version; BANNER Upgrade Oracle Database 10g Enterprise Edition Release 10.2.0.3.0-Prod PL/SQL Release 10.2.0.3.0-Production www.2cto.com CORE 10.2.0.3.0 Production TNS for 32-bit Windows: Version 10.2.0.3.0-Production NLSRTL Version 10.2.0.3.0-Production
Create the original table; SQL> create table testcol (a varchar2 (20), B varchar2 (20), d varchar2 (20 )); table created SQL> create table testcol_tmp (a varchar2 (20), B varchar2 (20), c varchar2 (20), d varchar2 (20 )); table createdinsert into testcol values ('1', '1', '1'); insert into testcol values ('2', '1', '1 '); insert into testcol values ('3', '1', '1'); SQL> select * from testcol; a B D ------------------------------------------ ------------------ 1 1 1 2 1 1 3 1 1 check whether the original table can be redefined online: SQL> exec partition ('Scott ', 'testcol'); begin dbms_redefinition.can_redef_table ('Scott ', 'testcol'); end; ORA-12089: The table without a primary key cannot be redefined online "SCOTT ". "TESTCOL" ORA-06512: In "SYS. DBMS_REDEFINITION ", line 137 ORA-06512: In" SYS. DBMS_REDEFINITION ", line 1478 ORA-06512: add a primary key SQL> alter table testcol add constr at line 2 www.2cto.com following the error prompt Aints pk_testcol primary key (a); Table altered: SQL> exec dbms_redefinition.can_redef_table ('Scott ', 'testcol'); PL/SQL procedure successfully completed passed. Start Online redefinition: SQL> exec dbms_redefinition.start_redef_table ('Scott ', 'testcol', 'testcol _ TMP ', 'a, B, d '); PL/SQL procedure successfully completed synchronize data: SQL> exec values ('Scott ', 'testcol', 'testcol _ TMP '); PL/SQL procedure successfully completed to complete online redefinition; SQL> exec dbms_redefinition.finish_redef_table ('Scott ', 'testcol', 'testcol _ TMP '); PL/SQL procedure successfully completed: www.2cto.com SQL> select * from testcol; a B c d -------------------------------------------------------------- 1 1 1 1 1 1 SQL> select * from testcol_tmp; a B D -------------------- 1 1 1 2 1 3 1 author Yafei Shi

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.