Oracle SQL to change column type from number to varchar2 while it contains data

后端 未结 4 1125
广开言路
广开言路 2020-12-31 22:27

I have a table (that contains data) in Oracle 11g and I need to use Oracle SQLPlus to do the following:

Target: change the type of column TEST1 in table

4条回答
  •  有刺的猬
    2020-12-31 23:09

    Add new column as varchar2, copy data to this column, delete old column, rename new column as actual column name:

    ALTER TABLE UDA1
    ADD (TEST1_temp  VARCHAR2(16));
    
    update UDA1 set TEST1_temp = TEST1;
    
    ALTER TABLE UDA1 DROP COLUMN TEST1;
    
    ALTER TABLE UDA1 
    RENAME COLUMN TEST1_temp TO TEST1;
    

提交回复
热议问题