2012-07-13 36 views
15

在Oracle中,我將數據從備份複製到新表,但不起作用。Oracle將數據複製到另一個表中

什麼是正確的語法?

感謝

select CODE, MESSAGE into EXCEPTION_CODES (CODE, MESSAGE) 
from Exception_code_tmp 

誤差

**SQL Error: ORA-00905: missing keyword 
00905. 00000 - "missing keyword"** 

回答

31

如果你想創建表的數據,您需要一個INSERT ... SELECT

INSERT INTO exception_codes(code, message) 
    SELECT code, message 
    FROM exception_code_tmp 
4
insert into EXCEPTION_CODES (CODE, MESSAGE) 
select CODE, MESSAGE from Exception_code_tmp 
+1

感謝。我們在Oracle中有「select .. into」嗎? – user595234 2012-07-13 14:36:51

+1

似乎並不如此根據[這篇文章](http://stackoverflow.com/questions/2250196/select-into-using-oracle) – 2012-07-13 14:43:25

22

。首先創建表:

create table new_table as (select * from old_table); 

,然後插入

insert into new_table (select * from old_table); 

如果不想數據來創建表。您可以使用:

create table new_table as (select * from old_table where 1=0); 
+9

'插入'是多餘的,因爲'創建表'將創建表並插入所有數據。 – thoredge 2016-09-07 13:45:09

7

創建一個表,並在單個命令複製數據:

create table T_NEW as 
    select * from T; 

*這將副本的PK,FKS,觸發器等

+0

在表格上覆制約束,例如不爲null。謝謝 :) – Shiva 2018-03-02 10:50:07

相關問題