首页 > 代码库 > Oracle中已有数据的字段类型修改

Oracle中已有数据的字段类型修改

Oracle中已有数据的字段类型修改

//建表 

create table t_person(  
id varchar2(200) primary key,  
name varchar2(200),  
address varchar2(200)  

);  

//插入数据

insert into t_person(id,name,address) values(sys_guid(),‘zhangsan‘,‘beijing‘);  
insert into t_person(id,name,address) values(sys_guid(),‘lisi‘,‘shangqiu‘);  
 
想把address的varchar2类型改为clob类型
(1)
[sql] 
alter table t_person rename column address to myaddress;  
把原字段换个名字,address改为myaddress
(2)
[sql] 
alter table t_person add address clob;  
在表中添加一个原字段名字 address 并把类型定义为自己想改变的类型,这里是clob
(3)
[sql] 
update t_person set address = myaddress;  
把备份的myaddress字段内容添加到新建字段address中来
(4)
[sql] 
alter table t_person drop column myaddress;  
把备份字段myaddress删除

Oracle中已有数据的字段类型修改