The COPY command is used to copy the data from a query to a table in a local or remote database. The COPY command can also be used to copy data to non-Oracle databases from an Oracle database.  For copy to a non-Oracle database, NUMBER columns become DECIMAL columns. For copy between two Oracle databases a NUMBER with no precision becomes a NUMBER(38).LONG values are limited to the length set by the SET LONG command. Any LONG data that is longer than the SET LONG value are truncated.Commits are perfromed at the end of each successful COPY. If you have a long copy cycle this can be detrimental to rollback and redo segments. Therefore you should use the SET commands COPYCOMMIT and ARRAYSIZE. The SET COPYCOMMIT establishes a set number of record batches that are processed between commits. The SET ARRAYSIZE parameter setting establishes the number of records per batch that are processed.Example 1 SQL> COPY FROM AULT/DBA_USER@TTEST TO SMITH/JONES@STATS
1: REPLACE MEASUREMENTS
2: USING SELECT * FROM MEASUREMENTS;In this command, the full table MEASUREMENTS is copied from user AULT/DBA_USER in the database specified by the TTEST database specifier to the user SMITH/JONES in the database specified by the STATS database specifier.Example 2 SQL> COPY FROM AULT/DBA_USER@TTEST TO SMITH/JONES@STATS
1: CREATE RESULTS (TEST_NO, INST_NO, MEASUREMENT)
2: USING SELECT (TEST_NO, INSTRUMENT, MEASURMENT) 
3: FROM TEST_TABLE A, MEASUREMENTS B
4: WHERE A.INSTRUMENT = B.MEASUREMENT;In this command, the table RESULTS is created as a two part select from the tables TEST_TABLE, MEASUREMENTS. The results are collected from user AULT/DBA_USER in the database specified by the TTEST specifier and the table created in the user SMITH/JONES in the database identified by the STATS specifier.

解决方案 »

  1.   

    忘了从哪个贴自看到,考了出来,打算自己试试。我再贴出来:
    How Do Bulk Binds Improve Performance?
    The assigning of values to PL/SQL variables in SQL statements is called binding.
    The binding of an entire collection at once is called bulk binding. Bulk binds improve
    performance by minimizing the number of context switches between the PL/SQL
    and SQL engines. With bulk binds, entire collections, not just individual elements,
    are passed back and forth. For example, the following DELETE statement is sent to
    the SQL engine just once, with an entire nested table:
    DECLARE
    TYPE NumList IS VARRAY(20) OF NUMBER;
    depts NumList := NumList(10, 30, 70); -- department numbers
    BEGIN
    ...
    FORALL i IN depts.FIRST..depts.LAST
    DELETE FROM emp WHERE deptno = depts(i);
    END;
    In the example below, 5000 part numbers and names are loaded into index-by
    tables. Then, all table elements are inserted into a database table twice. First, they
    are inserted using a FOR loop, which completes in 32 seconds. Then, they are
    bulk-inserted using a FORALL statement, which completes in only 3 seconds.SQL> SET SERVEROUTPUT ON
    SQL> CREATE TABLE parts (pnum NUMBER(4), pname CHAR(15));
    Table created.
    SQL> GET test.sql
    1 DECLARE
    2 TYPE NumTab IS TABLE OF NUMBER(4) INDEX BY BINARY_INTEGER;
    3 TYPE NameTab IS TABLE OF CHAR(15) INDEX BY BINARY_INTEGER;
    4 pnums NumTab;
    5 pnames NameTab;
    6 t1 NUMBER(5);
    7 t2 NUMBER(5);
    8 t3 NUMBER(5);
    9 PROCEDURE get_time (t OUT NUMBER) IS
    10 BEGIN SELECT TO_CHAR(SYSDATE,’SSSSS’) INTO t FROM dual; END;
    11 BEGIN
    12 FOR j IN 1..5000 LOOP -- load index-by tables
    13 pnums(j) := j;
    14 pnames(j) := ’Part No. ’ || TO_CHAR(j);
    15 END LOOP;
    16 get_time(t1);
    17 FOR i IN 1..5000 LOOP -- use FOR loop
    18 INSERT INTO parts VALUES (pnums(i), pnames(i));
    19 END LOOP;
    20 get_time(t2);
    21 FORALL i IN 1..5000 -- use FORALL statement
    22 INSERT INTO parts VALUES (pnums(i), pnames(i));
    23 get_time(t3);
    24 DBMS_OUTPUT.PUT_LINE(’Execution Time (secs)’);
    25 DBMS_OUTPUT.PUT_LINE(’---------------------’);
    26 DBMS_OUTPUT.PUT_LINE(’FOR loop: ’ || TO_CHAR(t2 - t1));
    27 DBMS_OUTPUT.PUT_LINE(’FORALL: ’ || TO_CHAR(t3 - t2));
    28* END;
    SQL> /
    Execution Time (secs)
    ---------------------
    FOR loop: 32
    FORALL: 3
    PL/SQL procedure successfully completed.
    To bulk-bind input collections, you use the FORALL statement. To bulk-bind output
    collections, you use the BULK COLLECT clause.