Solved

Changing data type on column with data already in it.

Posted on 2014-02-17
2
351 Views
Last Modified: 2014-03-24
Experts,

I have a table with a column for order quantities. Right now the column is varchar2. I need to change it to number.

Is it possible to do this without me having to empty out the table?

All of the rows have numbers in it.

Thanks,
0
Comment
Question by:FutureDBA-
2 Comments
 
LVL 23

Accepted Solution

by:
David earned 500 total points
ID: 39866422
Assuming no indexes/constraints:

ALTER TABLE table-Name
{
    ADD COLUMN column-definition |
    ADD CONSTRAINT clause |
    DROP [ COLUMN ] column-name [ CASCADE | RESTRICT ]
    DROP { PRIMARY KEY | FOREIGN KEY constraint-name | UNIQUE
       constraint-name | CHECK constraint-name | CONSTRAINT constraint-name }
    ALTER [ COLUMN ] column-alteration |
    LOCKSIZE { ROW | TABLE }
}
column-definition
Simple-column-Name [ DataType ]
[ Column-level-constraint ]*
[ [ WITH ] DEFAULT DefaultConstantExpression
  | generation-clause
]

column-alteration
column-Name SET DATA TYPE VARCHAR(integer) |
column-Name SET DATA TYPE VARCHAR FOR BIT DATA(integer) |
column-name SET INCREMENT BY integer-constant |
column-name RESTART WITH integer-constant |
column-name [ NOT ] NULL |
column-name [ WITH | SET ] DEFAULT default-value |
column-name DROP DEFAULT

source: http://docs.oracle.com/javadb/10.6.1.0/ref/rrefsqlj81859.html
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39867356
>>Is it possible to do this without me having to empty out the table?

The answer to your question is: yes.

The post above provides the syntax.

The alter table command will fail if there is data that Oracle cannot convert.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Concat multi row values of a field in oracle 6 66
Get FileTypes from a list of FileNames  in a Table field 18 50
Oracle query output question 4 43
Oracle DB monitor SW 21 50
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question