Oracle資料庫間的資料複製 - SQLPlus中的COPY命令

來源:互聯網
上載者:User

標籤: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:

  1. 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:

  1. 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命令比較長,可以在分行時每行末尾必須有續行符(-),最後一行不加。

    1. copy from scott/[email protected] -  
    2. to scott/[email protected]  
    3. create empy-  
    4. using select * from emp-  
    5. where rownum = 1  

Oracle資料庫間的資料複製 - SQLPlus中的COPY命令

相關文章

聯繫我們

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