欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Oracle表中已有數(shù)據(jù)修改字段類型方式

 更新時間:2023年12月02日 10:32:13   作者:sunday2018  
這篇文章主要介紹了Oracle表中已有數(shù)據(jù)修改字段類型方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

Oracle表中已有數(shù)據(jù)修改字段類型

Oracle的表中已存在了數(shù)據(jù),這時再來修改表的字段類型就無法修改。

例如:

number類型改成number(22),這時數(shù)據(jù)庫會報

ORA-01440: column to be modified must be empty to decrease precision or scale

推薦使用方法1,方法2如果字段不能為空就無法使用

方法1

備份原表數(shù)據(jù),清除表數(shù)據(jù),修改字段類型,還原數(shù)據(jù)

-- 1.創(chuàng)建備份表
create table test_bak as select * from test;
-- 2.清除原表數(shù)據(jù)
truncate table test;
-- 3.修改字段類型
alter table test modify test_id number(22);
-- 4.還原數(shù)據(jù)
insert into test select * from test_bak;
commit;

方法2

只備份需要修改的字段的數(shù)據(jù),可以在原表上新增備份字段,也可以新建一張表備份字段數(shù)據(jù)

-- 1.新增字段
alter table test add test_id_bak number;
-- 2.復制數(shù)據(jù)
update test set test_id_bak = test_id;
commit;
-- 3.清除字段數(shù)據(jù)并修改字段類型
update test set test_id = null;
commit;
-- 4. 修改字段類型
alter table test modify test_id number(22);
-- 5.還原數(shù)據(jù)
update test set test_id=test_id_bak;
commit;
-- 6.刪除臨時字段
alter table test drop column test_id_bak;

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論