RE: changing a column type

  • From: "Sweetser, Joe" <JSweetser@xxxxxxxx>
  • To: "gjilevski@xxxxxxxxx" <gjilevski@xxxxxxxxx>, "rui_catcuddler@xxxxxxxxx" <rui_catcuddler@xxxxxxxxx>
  • Date: Fri, 1 Jun 2012 19:35:38 +0000

As the link Guenadi sent describes, there are limitations but this is something 
that I never thought was possible until now.  Another reason to like hanging 
out here.  :)

Taking it one step further and expanding on Tim's example...

JSWEETSER@sandbox> create table test1 (pk number, col1 number, constraint 
joe_pk primary key (pk));

Table created.

JSWEETSER@sandbox> desc test1
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PK                                        NOT NULL NUMBER
 COL1                                               NUMBER

JSWEETSER@sandbox> insert into test1 values (1, 99);

1 row created.

JSWEETSER@sandbox> insert into test1 values (2, 200);

1 row created.

JSWEETSER@sandbox> create table test1_interim (pk number, col1 varchar2(30), 
constraint new_joe_pk primary key (pk));

Table created.

JSWEETSER@sandbox> desc test1_interim
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PK                                        NOT NULL NUMBER
 COL1                                               VARCHAR2(30)

JSWEETSER@sandbox> select * from test1_interim;

no rows selected

JSWEETSER@sandbox> exec dbms_redefinition.can_redef_table('JSWEETSER', 'TEST1');

PL/SQL procedure successfully completed.

JSWEETSER@sandbox> exec dbms_redefinition.start_redef_table ('JSWEETSER', 
'TEST1', 'TEST1_INTERIM', 'PK PK , to_char(col1) col1');

PL/SQL procedure successfully completed.

JSWEETSER@sandbox> col pk format 99
JSWEETSER@sandbox> col col1 format 999
JSWEETSER@sandbox> select * from test1;

 PK COL1
--- ----
  1   99
  2  200

JSWEETSER@sandbox> select * from test1_interim;

 PK
---
COL1
--------------------------------------------------------------------------------
  1
99

  2
200


JSWEETSER@sandbox> col col1 format a10
JSWEETSER@sandbox> select * from test1_interim;

 PK COL1
--- ----------
  1 99
  2 200

JSWEETSER@sandbox> desc test1
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PK                                        NOT NULL NUMBER
 COL1                                               NUMBER

JSWEETSER@sandbox> exec dbms_redefinition.finish_redef_table ('JSWEETSER', 
'TEST1', 'TEST1_INTERIM');

PL/SQL procedure successfully completed.

JSWEETSER@sandbox> desc test1
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PK                                        NOT NULL NUMBER
 COL1                                               VARCHAR2(30)

JSWEETSER@sandbox> select * from test1;

 PK COL1
--- ----------
  1 99
  2 200

JSWEETSER@sandbox>

-----Original Message-----
From: oracle-l-bounce@xxxxxxxxxxxxx [mailto:oracle-l-bounce@xxxxxxxxxxxxx] On 
Behalf Of Guenadi Jilevski
Sent: Friday, June 01, 2012 12:56 PM
To: rui_catcuddler@xxxxxxxxx
Cc: Brian.Zelli@xxxxxxxxxxxxxxx; oracle-l
Subject: Re: changing a column type

Hi,
Correct. Look at the example of dbms_redefinition. It is old but the idea
applies.

http://www.dbspecialists.com/files/presentations/online_redef.html

Regards,



On Fri, Jun 1, 2012 at 9:48 PM, Rui Cat <rui_catcuddler@xxxxxxxxx> wrote:

> As Mark and Tim showed not directly. Maybe looking at the
> dbms_redefinition package might help in this instance.
> Rui
>
>
> ________________________________
>  From: "Zelli, Brian" <Brian.Zelli@xxxxxxxxxxxxxxx>
> To: oracle-l <oracle-l@xxxxxxxxxxxxx>
> Sent: Friday, June 1, 2012 1:51:16 PM
> Subject: changing a column type
>
> A colleague wants to change a column type from numeric to alpha-numeric.
> Can he change it with data in it?
>
> ciao,
> Brian
>
> Brian Zelli
> Senior Database Administrator
> Enterprise Applications/Systems Integration
> Roswell Park Cancer Institute
> (716) 845-4460
> brian.zelli@xxxxxxxxxxxxxxx
>
>
>
> This email message may contain legally privileged and/or confidential
> information.  If you are not the intended recipient(s), or the employee or
> agent responsible for the delivery of this message to the intended
> recipient(s), you are hereby notified that any disclosure, copying,
> distribution, or use of this email message is prohibited.  If you have
> received this message in error, please notify the sender immediately by
> e-mail and delete this email message from your computer. Thank you.--
> //www.freelists.org/webpage/oracle-l
> --
> //www.freelists.org/webpage/oracle-l
>
>
>


--
//www.freelists.org/webpage/oracle-l



Confidentiality Note: This message contains information that may be 
confidential and/or privileged. If you are not the intended recipient, you 
should not use, copy, disclose, distribute or take any action based on this 
message. If you have received this message in error, please advise the sender 
immediately by reply email and delete this message. Although ICAT Managers, 
LLC, Underwriters at Lloyd's, Syndicate 4242, scans e-mail and attachments for 
viruses, it does not guarantee that either are virus-free and accepts no 
liability for any damage sustained as a result of viruses. Thank you.

--
//www.freelists.org/webpage/oracle-l


Other related posts: