COPY

COPY is a command in SQL utilized for copying data between a file and a table. It can be used to import data from a file into a table (COPY TO), or export data from a table into a file (COPY FROM).

Example

COPY customers TO '/usr1/proj/bray/sql/customers';

Output

COPY 22

Explanation

In the above sample, the COPY command is used to export data from the customers table to a file located at /usr1/proj/bray/sql/customers. If the command was successful, it returns the number of rows that are copied. In this case, 22 rows were copied to the file.

Example

COPY TO my_user/my_password@my_database CREATE my_table USING SELECT * FROM my_other_table;

Output

Array Fetch bind array size not set. (arraysize is 15)
Will commit when done. (copycommit is 0)
PL/SQL bind array size is 15.
Table MY_TABLE created.
Copying from MY_USER.MY_OTHER_TABLE to MY_USER.MY_TABLE:
15 rows selected from MY_USER.MY_OTHER_TABLE.
15 rows inserted into MY_USER.MY_TABLE.
15 rows committed in MY_USER.MY_TABLE.

Explanation

The COPY command above is used in SQL*Plus to copy data from one database to another. Here, the example provided creates MY_TABLE in the database specified (MY_DATABASE) with user MY_USER and password MY_PASSWORD. This new table is populated with data retrieved from MY_OTHER_TABLE using the SELECT * FROM MY_OTHER_TABLE statement. The output shows that the COPY command created MY_TABLE and copied 15 rows of data from MY_OTHER_TABLE into it.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.