Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: changing datatype
In article <36A34D64.6FE010BD_at_uk.ibm.com>, Richard <gbdslrba_at_uk.ibm.com> wrote:
>I have a table with about 20 columns (including a long raw) and about
>60000 rows. I want to change the datatype of one of the columns from
>number to varchar2. I understand that the column must be empty to do
>this and so tried exporting the table, clearing the table and changing
>the datatype and then, unsuccessfully, tried reimporting.
>Does anyone know if, and how, it is possible to change a datatype and
>keep the data?
You can change the datatype only if the column has only null values; You can increase the length anytime, but can only decrease it if all values are null. My preferred method (for non-giant tables at least) is:
This assumes that MyTable is not being updated. If MyTable is huge, you may need an index on TmpTable.PrimaryKey. If it is really huge, perhaps create one with the new definition, insert as select from original, drop original, rename new to original name, and recreate necessary triggers, constraints, and indexes.