oracle----複製表中的資料

來源:互聯網
上載者:User

標籤:

兩種方法:

1. 在建立表的時候將資料從其他表中複製過來(並且表的結構也複製過來):

文法:

 

CREATE TABLE table_nameASSELECT column1,......|* FROM table_old;
SQL>SQL> create table userinfo_new  2  AS  3  SELECT * from userinfo;表已建立。SQL> desc userinfo_new; 名稱                                      是否為空白? 類型 ----------------------------------------- -------- ---------------------------- ID                                                 NUMBER(6) USERNAME                                           VARCHAR2(20) USERPWD                                            VARCHAR2(20) EMAIL                                              VARCHAR2(30) REGDATE                                            DATESQL>

值也複製了:

SQL> select * from userinfo_new;        ID USERNAME             USERPWD---------- -------------------- --------------------EMAIL                          REGDATE------------------------------ --------------         1 xxx                  123456ltwuyanlong@163.com            20-9月 -15         2 yyy                  456123         3無        ID USERNAME             USERPWD
SQL> desc userinfo_new1 名稱                                      是否為空白? 類型 ----------------------------------------- -------- ---------------------------- ID                                                 NUMBER(6) USERNAME                                           VARCHAR2(20)SQL> select * from userinfo_new1;        ID USERNAME---------- --------------------         1 xxx         2 yyy         3         4SQL>

 

---------- -------------------- --------------------EMAIL                          REGDATE------------------------------ --------------         4631464569@163.comSQL>

 

 

2. 在添加資料的時候將資料從其他表中複製過來:

文法:

INSERT INTO table_name[(column1,column2,...)]select column1,column2,.....| from table_old

這種情況下必須要求兩張表都已經存在了才可以使用!

SQL> insert into userinfo_new  2  select * from userinfo;已建立4行。SQL> select id from userinfo_new;        ID----------         1         2         3         4         1         2         3         4已選擇8行。SQL>

指定插入欄位:

SQL>SQL> insert into userinfo_new(id,username)  2  select id,username from userinfo;已建立4行。SQL> select id ,username from userinfo_new;        ID USERNAME---------- --------------------         1 xxx         2 yyy         3         4         1 xxx         2 yyy         3         4         1 xxx         2 yyy         3        ID USERNAME---------- --------------------         4已選擇12行。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.