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

后端 未结 4 1177
广开言路
广开言路 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:05

    Here you go, this solution did not impact the existing NOT NULL or Primary key constraints. Here i am going to change the type of Primary key from Number to VARCHAR2(3), Here are the Steps on example table employee.

    1. Take backup of table and Index, Constraints created table employee_bkp create table employee_bkp as select * from employee commit;
    2. Truncate the table to empty it truncate table employee
    3. Alter the table to change the type ALTER TABLE employee MODIFY employee_id varchar2(30);
    4. Copy the data back from backup table insert into employee (select * from employee_bkp) commit;
    5. Verify

提交回复
热议问题