Actual usage of the Oracle Copy command

Source: Internet
Author: User

The following articles mainly describe the Oracle Copy command. The Oracle Copy command in SQL * Plus copies data between related human data tables, which is one of the tasks that Oracle DBA often faces, oracle provides a variety of solutions for this task. The SQL * Plus Copy command is one of them.

The SQL * Plus Copy command uses SQL * Net to Copy or move data between different tables (the same server or different servers.

In the actual running environment, selecting the SQL * Plus Copy command can effectively improve the data replication performance.

The following describes how to use the SQL * Plus Copy Command, and compares the performance with the other two solutions, so as to provide a reference for using the Copy command.

1. syntax and usage instructions

1.1 syntax

Next, let's take a look at the syntax and usage of the SQL * Copy command.

Before interpreting the syntax of the SQL * Plus Copy command, we must clarify that the SQL * Plus Copy command is neither a method nor a function nor an SQL statement. It is a command ), of course, this command must be run in SQL * Plus.

Syntax of the SQL * Plus Copy command:

 
 
  1. COPY {FROM database | TO database | FROM database TO database} 
    {APPEND|CREATE|INSERT|REPLACE} destination_table [(column, column, column, ...)]  
  2. USING query 

Here, we will explain the Division:

COPY-this does not need to be explained. The main command declares to execute the Oracle COPY operation.

From Database-source Database

To Database-target Database

Note that there are three optional statements in brackets (separated by "|"). If the source and target data tables are in the same Schema, you can write only From Database, you can also write only To Database. Of course, it can also be the third method, which fully writes From Database and To Database. However, if the source and target data tables are not in the same Schema, you must write the From Database and To Database in the third way.

The format of From Database and To Database is the same: USERID/PASSWORD @ SID, which should be familiar To everyone.

{APPEND | CREATE | INSERT | REPLACE}-Method of declaring operation data. The following describes the methods respectively:

Append-Append a record to an existing target table. If the target table does not exist, it is automatically created. This is equivalent to Create.

Create-Create a target table and add records to it. If the target table already exists, an error is returned.

Insert-Insert a record into an existing target table. Unlike Append, if the target table does not exist and is not created automatically, an error is returned.

Replace-overwrite existing data in the target table with the queried data. If the target table does not exist, it is automatically created.

Destination_table-name of the target table

[(Column,...)]-You can specify the name of the column in the target table. If this parameter is not specified, the column name in the Query is automatically used.

USING query-query statement. The exchange data comes from here.

1.2 example

The following example shows how to use the SQL * Plus Copy command:

1.2.1 copy data in the same Schema of the same server:

Specify both From database and To database

 
 
  1. SQL> copy from scott/tiger@lsj to scott/tiger@lsj create dept1 using select * from dept; 

Specify From Database only

 
 
  1. SQL> copy from scott/tiger@lsj create dept2 using select * from dept; 

Specify To Database only

 
 
  1. SQL> copy to scott/tiger@lsj create dept3 using select * from dept; 

1.2.2 copy data in different schemas of the same server:

In this case, both From Database and To Database must be specified.

 
 
  1. SQL> copy from scott/tiger@lsj to lsjdemo/lsjdemo@lsj 
    create dept using select * from dept; 

Note that in this case, the form of scott. demp is not required in using select * from dept.

1.2.3 copy data between different servers:

 
 
  1. SQL> conn lsj/lsj@sunserve 

Connected.

 
 
  1. SQL> copy from scott/tiger@lsj to lsj/lsj@sunserve create dept using select * from dept; 

2.4 Performance Experiment Results

Lab data:

Number of records: 5,082,500

Data volume: 504 MB

Lab results

Solution ------------------------ execution time (seconds) --------- Undo (M) ------ Redo (M)

Copy command ------------- 520.51 ------------------------ 0 ---------------- 592

Insert... Select... ---- 631.64 ------------------ 345 ------------- 1720

Create Table... ------------- 244.79 -------------------- 0 ---------------- 515

2. Summary

Create Table... As select... It is the fastest and generates the least Undo and Redo information. Therefore, use this solution whenever possible. However, this scheme has certain limitations, that is, the target table must not exist and cannot be used to append records to the existing target table.

Insert... Select... It is the slowest, and generates the most Undo and Redo information, which puts the most pressure on I/O. The advantage is that you are familiar with it and easy to use. It is suitable for processing a small amount of data, this solution is not recommended if you want to process a large amount of data.

Oracle Copy Command can deal with situations where the Create Table cannot be processed, that is, to append records to existing data tables, which is more efficient than insert, generates less Redo information and does not generate Undo information, therefore, the Copy Command is recommended when a large amount of data is appended.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.