標籤:des http io 使用 ar strong 資料 art sp
Copy命令可以實現不同Oracle資料庫間的資料的複製,也是可以實現同一資料庫的資料複製,其效能表現和匯入/匯出相同。
根據9i文檔,說Copy命令未來會不支援,但實際上Oracle 11g仍然支援Copy命令,只是未寫入11g的文檔裡,未來12C不知道還支不支援。
Copy也有明顯的缺點,Copy只支援五種資料類型,Char,Date,Long,Number,Varchar2,8i之後Oracle資料庫新增的資料類型都不支援。
使用方法:
1.首先確保TNS裡記錄了源Instance和目標Instance的串連資訊;
2.運行SQL * Plus(無需串連具體的Instance)
sqlplus /nolog
3.運行Copy命令
Copy命令的文法:
COPY {FROM database | TO database | FROM database TO database} {APPEND|CREATE|INSERT|REPLACE} destination_table [(column, column, column, ...)]
USING query
where database has the following syntax:
username[/password]@connect_identifier
Copies data from a query to a table in a local or remote database. COPYsupports the following datatypes:
CHAR
DATE
LONG
NUMBER
VARCHAR2
Example:
- copy from user1/[email protected]_instance to user2/[email protected]_instance create emp2 using select * from emp;
上邊的命令會從source_instance中把emp資料拷貝到dest_instance中的emp2表。
資料庫內的複製,也可以使用Copy命令,Example:
- copy from scott/[email protected] to scott/[email protected] create emp2 using select * from emp;
這就有點類似於CREATE TABLE empx AS (SELECT * FROM emp);
根據Tom的說法,Copy 的效率可能會比CREATE TABLE ... AS ...(資料庫間的複製也可以使用Create table...as,通過database Link)差,因為Copy是把資料從一個Instance拷貝到sqlplus,再從sqlplus插入另外一個Instance。
而CREATE TABLE ... AS ...是把一個資料庫的資料直接插入到第二個資料庫,所以效率會高一些。
Copy 命令的四種模式
* replace子句指定了被建立的表名。如果目標表已存在,則刪除並用包含複製資料的表替代。若不存在,則建立目標表。
* 使用create子句可避免覆蓋已存在的表。若目標表已存在,則copy報告一個錯誤;若不存在,則建立目標表。
* insert插入資料到已存在的表。將查詢到的行插入到目標表,如果目標表不存在,copy返回錯誤。當使用insert時,using子句必須為目標表的每個列選擇對應的列。
* append是將查詢到的行插入到目標表。如果不存在,則建立目標表並插入。
其他說明
如果copy命令比較長,可以在分行時每行末尾必須有續行符(-),最後一行不加。
- copy from scott/[email protected] -
- to scott/[email protected]
- create empy-
- using select * from emp-
- where rownum = 1
Oracle資料庫間的資料複製 - SQLPlus中的COPY命令