oracle varchar2改成大字段类型clob,读取大字段内容

oracle varchar2(4000)改成大字段类型clob,如果需要改成大字段的varchar2列有内容,不能直接用

alter table med_generic modify option07 blob;

直接用上面的会提示:ORA-22858: 数据类型的变更无效

因此,修改应采用下面的方法:

--增加大字段项
alter table med_generic add hehe clob;
--将需要改成大字段的项内容copy到大字段中
update med_generic set hehe=option07;
--删除原有字段
alter table med_generic drop column option07;
--将大字段名改成原字段名
alter table med_generic rename column hehe to option07;

此时原option07的内容都到新建的hehe(clob类型),且原option07字段删除了,hehe字段名称改为option07字段

直接查询:

select g.option07 from med_generic g where g.medname='amxl';

若要直接查出大字段的内容,可将sql改为:

select dbms_lob.substr(g.option07) from med_generic g where g.medname='amxl';

猜你喜欢

转载自blog.csdn.net/zdb292034/article/details/81114485