Use the sqlplus Copy command to transfer data between two databases

Source: Internet
Author: User

This article describes how to use the sqlplus Copy command to transfer data between two databases.

Dblink is not required, and two databases do not need to communicate directly. Of course, there must be a client segment that can be connected to both databases with sqlplus at the same time.

Question proposal

Someone raised the following question on the Forum:

Assume that two databases are in two different networks, but one client has two NICs that can be connected to the two databases at the same time. If you do not create a transit table on the client, is there a way to copy tables from one database to another.

Answers to questions

You can use the copy command of sqlplus.

The Copy command looks like this:

Usage: copy from <dB> to <dB> <opt> <Table >{( <Cols>)} using <sel><DB>: Database string, e.g., Scott/tiger @ D: Chicago-mktg
<Opt>: One of the keywords: append, create, insert or replace
<Table>: name of the destination table
<Cols>: A comma-separated list of destination column aliases
<Sel>: Any valid SQL SELECT statement

In fact, it should be very clear to write, according to that syntax can be completed.

It is equivalent to extracting data from the from dB to the buffer according to <sel>, and then creating a table (Create) Or re-create a table (Replace), And then put the dataInsertOrAppendInsert to the table of the database.

Note that a higher value is usually set.ArraysizeTo reduce the interaction between sqlplus and dB to achieve better performance.

In addition, you do not need to write a password when writing the database string. sqlplus will prompt you to enter the password later.

A complete example:

Sqlplus/nolog

SQL> set arraysize 5000

SQL> copy from serol/LUO @ mescp to serol/LUO @ ractest create test_copy_table using select * From dba_objects;

Array fetch/Bind size is 5000. (arraysize is 5000)
Will commit when done. (copycommit is 0)
Maximum long size is 5000. (Long is 5000)
Sqlrcn in cpytbl failed:-2120.
Table test_copy_table created.
12579 rows selected from serol @ mescp.
12579 rows inserted into test_copy_table.
12579 rows committed into test_copy_table at serol @ ractest.

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.