Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting a number column to a varchar2

orausernOct 30 2012 — edited Oct 30 2012
Hi ,
We are on 11.2.0.2 on Solaris 10. I have a need to convert a column which is a number data type to a VARCHAR2 data type. The table has data and the column is part of the primary key. Is it possible? How best can one go about it?
 
SQL>  create table test1 
(object_name varchar2(30) NOT NULL, object_id number NOT NULL); 


Table created. 

SQL>ALTER TABLE TEST1 add(constraint test1_pk primary key (OBJECT_NAME,OBJECT_ID)); 


Table altered. 

SQL> INSERT INTO TEST1 VALUES('EMP',1); 

1 row created. 

SQL> ED 
Wrote file afiedt.buf 

  1* INSERT INTO TEST1 VALUES('DEPT',2) 
SQL> / 

1 row created. 

SQL> COMMIT; 

Commit complete. 

SQL> ALTER TABLE TEST1 MODIFY (OBJECT_ID VARCHAR2(20)); 
ALTER TABLE TEST1 MODIFY (OBJECT_ID VARCHAR2(20)) 
                          * 
ERROR at line 1: 
ORA-01439: column to be modified must be empty to change datatype 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2012
Added on Oct 30 2012
9 comments
17,484 views