Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 17:36:10
Original
1139 people have browsed it

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template