oracle中更改欄位資料型別
阿新 • • 發佈:2018-12-10
–新增臨時列 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也更多,前提也是要停機才進行操作,如果不停機 ,也可以採用線上重定義方式來做。