>  기사  >  데이터 베이스  >  Oracle 如何修改列不为空的时候的数据类型

Oracle 如何修改列不为空的时候的数据类型

WBOY
WBOY원래의
2016-06-07 17:36:101095검색

ndash;新增临时列 alter table tablename add filedname_temp number(2); ndash;将临时列的值置空 update zyt set id_temp=nul

–新增临时列

alter table tablename add filedname_temp number(2);

–将临时列的值置空

update zyt set id_temp=null; -----#alter table tablename modify filedname null;

–将要更新的字段值挪到临时列,并置空该列

update tablename set filedname_temp=filedname,filedname=null;

commit;

–修改列的数据类型为varchar2

alter table tablename modify filedname varchar2(20);

–将要临时列值重新挪到该列,并置空临时列

update tablename set filedname=filedname_temp,filedname_temp=null;

commit;

–删除临时列

alter table tablename drop column filedname_temp;

–给该列不能为空

alter table tablename modify filedname not null;

–执行查询测试

select * from tablename ;

使用这种方式,既不用使列名发生变化,也不会发生表迁移,但有个缺点是表要更新两次,而且当如果数据量较大时,,产生的undo和redo也更多,前提也是要停机才进行操作,如果不停机 ,也可以采用在线重定义方式来做。

注:请自行更换tablename和filedname为自己的实际值。

linux

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.