Home » SQL & PL/SQL » SQL & PL/SQL » change the datatype of a field without empty the existing one.
change the datatype of a field without empty the existing one. [message #10867] Sat, 21 February 2004 00:11 Go to next message
shahzad
Messages: 17
Registered: February 2002
Junior Member
dear sir, pls update the table field....or change the datatype of existing field....
.......................example.........................
field1 number(6) i want to change this into
field varchar2(10)....it is possible.....
i get the following error....
ERROR at line 2:
ORA-01439: column to be modified must be empty to change datatype
pls help mei urgent
Re: change the datatype of a field without empty the existing one. [message #10868 is a reply to message #10867] Sat, 21 February 2004 03:13 Go to previous messageGo to next message
Mubasher
Messages: 4
Registered: December 2003
Junior Member
Mr. Shahzad
You can not change the name of field names, but u can change the datatype or length. Please try without changing the name.
OK
Re: change the datatype of a field without empty the existing one. [message #10878 is a reply to message #10868] Sat, 21 February 2004 12:04 Go to previous messageGo to next message
gomes009
Messages: 3
Registered: February 2004
Junior Member
Add a new column field varchar2(10) to the table.

Update field varchar2(10) with the values in field1 number(6) of the table.

After successful update, drop the field1 number(6)
column from the table

Rename the field varchar2(10) to field1 in the table
Re: change the datatype of a field without empty the existing one. [message #10879 is a reply to message #10868] Sat, 21 February 2004 12:31 Go to previous message
William Robertson
Messages: 1643
Registered: August 2003
Location: London, UK
Senior Member
> You can not change the name
Well in 9i (at last) you can:

SQL*Plus: Release 9.2.0.1.0 - Developer's Release on Sat Feb 21 22:04:00 2004

SQL> CREATE TABLE testit (id INTEGER PRIMARY KEY);

Table created.

SQL> desc testit
 Name                          Null?    Type
 ----------------------------- -------- --------------------
 ID                            NOT NULL NUMBER(38)

SQL> ALTER TABLE testit RENAME COLUMN id TO testit_id;

Table altered.

SQL> desc testit
 Name                          Null?    Type
 ----------------------------- -------- --------------------
 TESTIT_ID                     NOT NULL NUMBER(38)

SQL> @constr testit

Type     Constraint name           Definition                                         Status
-------- ------------------------- -------------------------------------------------- --------
Primary  SYS_C001660               Primary key (TESTIT_ID)                            ENABLED

SQL> ALTER TABLE testit RENAME CONSTRAINT SYS_C001660 TO testit_pk;

Table altered.

SQL> @constr

Type     Constraint name           Definition                                         Status
-------- ------------------------- -------------------------------------------------- --------
Primary  TESTIT_PK                 Primary key (TESTIT_ID)                            ENABLED

SQL> 
Previous Topic: Help to write SQL scripts please.
Next Topic: Clob to string conversion
Goto Forum:
  


Current Time: Wed Apr 24 06:26:49 CDT 2024