Oracle 增加、修改、刪除、重新命名列

來源:互聯網
上載者:User

標籤:oracle   列操作   

因為Oracle對於列的增刪改操作格式略有不同,為了方便日後查看,特此記錄。

1、增加列:

        SQL> alter table t1 add y integer;

         

        Table altered

         

        Executed in 0.046 seconds

        說明:增加列的格式為 alter table 表名 add 新增列名 資料類型;


2、刪除列

        SQL> alter table t1 drop column y;

         

        Table altered

         

        Executed in 0.015 seconds


       說明:單獨刪除一列的格式為 alter table 表名 drop column 列名;


3、修改列

       SQL>alter table t1 modify i number(10);

       說明:修改列的格式為 alter table 表名 modify 列名 資料類型;

       特別注意:如需更改列資料類型,轉換前需要備份列資料後清除列資料,否則更改失敗!


4、重新命名列

        SQL> alter table t1 rename column i to x;

         

        Table altered

         

        Executed in 0.062 seconds


       說明:重新命名列的格式為 alter table 表名 rename column 列名 to 新列名;、


5、刪除多列


        SQL> alter table t drop (a,b);

         

        Table altered

         

        Executed in 1.56 seconds


       說明:同時刪除多列的格式為 alter table 表名 drop (列名1,列名2,....列名N);

       同時需要說明的是,同時刪除多列不能把表中的所有列都刪除,如果都刪除表就沒有任何意義。


最後,稍稍地鄙視一下oracle的開發人員,sql命令語句格式一點都不規範,過於隨意!



Oracle 增加、修改、刪除、重新命名列

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.