Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everybody ...
I have an oracle 10g db ,I want to modify a column datatype in a table , this column is not empty , it contains some data , I was advised to create a new column , move the old data to it , modify the old column data type , then return the data back to this column ... Is this the best solution ??? If so ... how to implement it ??? what is the script (I want to change the data type from nvarchar2 to varchar2)

thanks in advance...
Posted

1 solution

No need to copy the data twice. Have a look at this tiny script:
SQL
ALTER TABLE mytable ADD new_column VARCHAR2(64); --exchange 64 for the size you need
UPDATE mytable SET new_column = old_column;
ALTER TABLE mytable DROP COLUMN old_column;
ALTER TABLE mytable RENAME COLUMN new_column to old_column;
There is no error checking done here. I'm assuming here that the implicit conversion from nvarchar to varchar is doable without problems.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900