RE: changing a column type

From: Mercadante, Thomas F (LABOR) <"Mercadante,>
Date: Mon, 4 Jun 2012 08:29:10 -0400
Message-ID: <AD4532B304E00C4F9AEFA0D338DF7DD10D184D5C55_at_excnysm95banp.nysemail.nyenet>



Brian,

Kinda late to the game but here is another way:

Given
Test_table(col1 number(10));

And we want
Test_table(col1 varchar2(10));

Alter table test_table add(new_col1 varchar2(10)); Update test_table
Set new_col1 = col1;
Commit;
-- check the data to make sure it all migrated correctly;
Alter table test_table drop column col1; Alter table test_table rename column new_col1 to col1;

Hope this helps.

Tom

-----Original Message-----

From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Zelli, Brian Sent: Friday, June 01, 2012 2:49 PM
To: oracle-l
Subject: RE: changing a column type

I thought you would not be able to change it with data in it but he told me he has in the past. I wasn't so sure......

ciao,
Brian

-----Original Message-----

From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Powell, Mark Sent: Friday, June 01, 2012 2:43 PM
To: oracle-l
Subject: RE: changing a column type

Observe:

MPOWEL01_at_UT1> create table marktest2 ( fld1 number, fld2 varchar2(30));

Table created.

MPOWEL01_at_UT1> insert into marktest2 values (1,'something or other');

1 row created.

MPOWEL01_at_UT1> commit;

Commit complete.

MPOWEL01_at_UT1> alter table marktest2 modify (fld1 varchar2(10)); alter table marktest2 modify (fld1 varchar2(10))

                              *

ERROR at line 1:
ORA-01439: column to be modified must be empty to change datatype

MPOWEL01_at_UT1>

-----Original Message-----

From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Zelli, Brian Sent: Friday, June 01, 2012 1:51 PM
To: oracle-l
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

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.-- http://www.freelists.org/webpage/oracle-l

--

http://www.freelists.org/webpage/oracle-l Received on Mon Jun 04 2012 - 07:29:10 CDT

Original text of this message