Yesterday, I have post Changing Data Type of Non Empty Column In Oracle
Tonguc made me to investigate with DBMS_REDEFINITION supplied package that you make online DDL modifications with his post. I made a simple example:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as SYS
SQL> create table z( i number);
Table created
SQL> create table zzz( i varchar2(12));
Table created
SQL> INSERT INTO z VALUES( 4);
1 row inserted
SQL> commit;
Commit complete
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','i i');
begin dbms_redefinition.start_redef_table(user,'z','zzz','i i'); end;
ORA-12087: online redefinition not allowed on tables owned by "SYS"
ORA-06512: at "SYS.DBMS_REDEFINITION", line 50
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1343
ORA-06512: at line 1
SQL> drop table z;
Table dropped
SQL> drop table zzz;
Table dropped
SQL> grant execute on dbms_redefinition to hr;
Grant succeeded
SQL> grant CREATE ANY TABLE, ALTER ANY TABLE, DROP ANY TABLE, LOCK ANY TABLE, SELECT ANY TABLE to hr;
Grant succeeded
SQL> conn hr/hr
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> create table z( i number);
Table created
SQL> INSERT INTO z VALUES( 4);
1 row inserted
SQL> commit;
Commit complete
SQL> create table zzz( i varchar2(12));
Table created
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','i i');
begin dbms_redefinition.start_redef_table(user,'z','zzz','i i'); end;
ORA-12089: cannot online redefine table "HR"."Z" with no primary key
ORA-06512: at "SYS.DBMS_REDEFINITION", line 50
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1343
ORA-06512: at line 1
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','i i',2);
begin dbms_redefinition.start_redef_table(user,'z','zzz','i i',2); end;
ORA-42016: shape of interim table does not match specified column mapping
ORA-06512: at "SYS.DBMS_REDEFINITION", line 50
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1343
ORA-06512: at line 1
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','to_char(i) i',2);
PL/SQL procedure successfully completed
SQL> INSERT INTO z VALUES( 41);
1 row inserted
SQL> INSERT INTO z VALUES( 411);
1 row inserted
SQL> commit;
Commit complete
SQL> exec dbms_redefinition.sync_interim_table(user,'z','zzz');
PL/SQL procedure successfully completed
SQL> exec dbms_redefinition.finish_redef_table(user,'z','zzz');
PL/SQL procedure successfully completed
SQL> desc z;
Name Type Nullable Default Comments
---- ------------ -------- ------- --------
I VARCHAR2(12) Y
SQL> SELECT * FROM z;
I
------------
4
41
411
SQL>
Tonguc made me to investigate with DBMS_REDEFINITION supplied package that you make online DDL modifications with his post. I made a simple example:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as SYS
SQL> create table z( i number);
Table created
SQL> create table zzz( i varchar2(12));
Table created
SQL> INSERT INTO z VALUES( 4);
1 row inserted
SQL> commit;
Commit complete
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','i i');
begin dbms_redefinition.start_redef_table(user,'z','zzz','i i'); end;
ORA-12087: online redefinition not allowed on tables owned by "SYS"
ORA-06512: at "SYS.DBMS_REDEFINITION", line 50
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1343
ORA-06512: at line 1
SQL> drop table z;
Table dropped
SQL> drop table zzz;
Table dropped
SQL> grant execute on dbms_redefinition to hr;
Grant succeeded
SQL> grant CREATE ANY TABLE, ALTER ANY TABLE, DROP ANY TABLE, LOCK ANY TABLE, SELECT ANY TABLE to hr;
Grant succeeded
SQL> conn hr/hr
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> create table z( i number);
Table created
SQL> INSERT INTO z VALUES( 4);
1 row inserted
SQL> commit;
Commit complete
SQL> create table zzz( i varchar2(12));
Table created
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','i i');
begin dbms_redefinition.start_redef_table(user,'z','zzz','i i'); end;
ORA-12089: cannot online redefine table "HR"."Z" with no primary key
ORA-06512: at "SYS.DBMS_REDEFINITION", line 50
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1343
ORA-06512: at line 1
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','i i',2);
begin dbms_redefinition.start_redef_table(user,'z','zzz','i i',2); end;
ORA-42016: shape of interim table does not match specified column mapping
ORA-06512: at "SYS.DBMS_REDEFINITION", line 50
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1343
ORA-06512: at line 1
SQL> exec dbms_redefinition.start_redef_table(user,'z','zzz','to_char(i) i',2);
PL/SQL procedure successfully completed
SQL> INSERT INTO z VALUES( 41);
1 row inserted
SQL> INSERT INTO z VALUES( 411);
1 row inserted
SQL> commit;
Commit complete
SQL> exec dbms_redefinition.sync_interim_table(user,'z','zzz');
PL/SQL procedure successfully completed
SQL> exec dbms_redefinition.finish_redef_table(user,'z','zzz');
PL/SQL procedure successfully completed
SQL> desc z;
Name Type Nullable Default Comments
---- ------------ -------- ------- --------
I VARCHAR2(12) Y
SQL> SELECT * FROM z;
I
------------
4
41
411
SQL>
No comments:
Post a Comment