COPY

Purpose

Copies the data from a query to a table in a local or remote database. COPY supports the following datatypes:

CHAR
DATE
LONG
NUMBER
VARCHAR2

Syntax

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

Terms and Clauses

Refer to the following list for a description of each term or clause:

FROM database
TO database
database
APPEND
CREATE
INSERT
REPLACE
destination_table
(column, column, column, ...)
USING query

Usage Notes

To enable the copying of data between Oracle and non-Oracle databases, NUMBER columns are changed to DECIMAL columns in the destination table. Hence, if you are copying between Oracle databases, a NUMBER column with no precision will be changed to a DECIMAL(38) column. When copying between Oracle databases, you should use SQL commands (CREATE TABLE AS and INSERT) or you should ensure that your columns have a precision specified.

The SQL*Plus SET variable LONG limits the length of LONG columns that you copy. If any LONG columns contain data longer than the value of LONG, COPY truncates the data.

SQL*Plus performs a commit at the end of each successful COPY. If you set the SQL*Plus SET variable COPYCOMMIT to a positive value n, SQL*Plus performs a commit after copying every n batches of records. The SQL*Plus SET variable ARRAYSIZE determines the size of a batch.

Some operating environments require that service names be placed in double quotes.

Examples

The following command copies the entire EMP table to a table named WESTEMP. Note that the tables are located in two different databases. If WESTEMP already exists, SQL*Plus replaces the table and its contents. The columns in WESTEMP have the same names as the columns in the source table, EMP.

SQL> COPY FROM SCOTT/TIGER@HQ TO JOHN/CHROME@WEST -
> REPLACE WESTEMP -
> USING SELECT * FROM EMP

The following command copies selected records from EMP to the database to which SQL*Plus is connected. SQL*Plus creates SALESMEN through the copy. SQL*Plus copies only the columns EMPNO and ENAME, and at the destination names them EMPNO and SALESMAN.

SQL> COPY FROM SCOTT/TIGER@HQ -
> CREATE SALESMEN (EMPNO,SALESMAN) -
> USING SELECT EMPNO, ENAME FROM EMP -
> WHERE JOB='SALESMAN'