Oracle如何修改列不為空白的時候的資料類型

來源:互聯網
上載者:User

   –新增臨時列

  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為自己的實際值。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.