美文网首页
oracle修改字段类型由varchar2修改为clob类型

oracle修改字段类型由varchar2修改为clob类型

作者: 安易学车 | 来源:发表于2021-09-09 15:57 被阅读0次

发现clob类型比较特殊,和其他字段类型不同,不可以从其他字段类型直接转换为clob(blob也一样),可以通过long类型作为中间转换的桥梁,即先将varchar2转换为long,然后再将long转换为clob,即可。

SQL> alter table test modify (loc long );

Table altered

SQL> alter table test modify (loc clob );

Table altered

2、假设要修改字段有数据,则可以使用以下两种方法;

方法一:

alter table batchintfloadlog rename column resultinfo to resultinfo_temp;

alter table batchintfloadlog add resultinfo clob;

update batchintfloadlog set resultinfo=trim(resultinfo_temp);

alter table batchintfloadlog drop column resultinfo_temp;

方法二:

create table batchintfloadlog_temp  as select * from batchintfloadlog where 1=2; 

alter table batchintfloadlog_temp modify (resultinfo long); 

alter table batchintfloadlog_temp modify (resultinfo clob); 

insert into batchintfloadlog_temp select * from batchintfloadlog;

drop table batchintfloadlog; 

rename batchintfloadlog_temp to batchintfloadlog;

相关文章

网友评论

      本文标题:oracle修改字段类型由varchar2修改为clob类型

      本文链接:https://www.haomeiwen.com/subject/mzoiwltx.html