Comparison between Oracle's Copy command and create table and insert

Source: Internet
Author: User

Copying data between data tables is one of the tasks that Oracle DBAs often face. 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.

China Network Management Alliance bitscn.com

 

Syntax of the SQL * Plus Copy command:
Network Management Alliance bitscn_com

Copy {from database | to database | from database to database} {append | create | insert | replace} destination_table [(column,...)]
Using Query

Here, we will explain the Division:

Copy-this does not need to be explained. The main command declares to execute the 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. Www_bitscn_com

{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
SQL> copy from Scott/tiger @ lsj to Scott/tiger @ lsj create dept1 using select * from Dept;
Specify from database only
SQL> copy from Scott/tiger @ lsj create dept2 using select * from Dept; China Network Management Alliance bitscn.com
Specify to database only
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.
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:
SQL> conn lsj/lsj @ sunserve
Connected.
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

Network Management Forum bbs_bitscn_com

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.
Copy command can process the situations where the create table cannot be processed, that is, to append records to an existing data table. Compared with insert, the copy command is more efficient and generates less redo information without generating undo information, therefore, the copy command is recommended when a large amount of data is appended.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/yanleigis/archive/2008/10/13/3066942.aspx

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.