您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

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

2024/4/26 3:34:35发布6次查看
新增临时列 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=file
–新增临时列
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为自己的实际值。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录