SQLPlUS Copy命令学习笔记_20110806

Oracle 10g开始在SQLPLUS中引入了Copy命令

SQLPLUS Copy命令可以在不同的数据库之间或不同的用户之间拷贝表数据,且表带有Long字段不能使用CTAS时相当有用;

示例:
sqlplus /nolog
set long 1000       
set copycommit 10   
set arraysize 5000  
copy from test/test@testdb1 to mouse/mouse@testdb2 create new_t using select * from t;
copy from test/test@testdb1 to mouse/mouse@testdb2 insert new_t using select * from t;
copy from test/test@testdb1 to mouse/mouse@testdb2 append new_t using select * from t;
copy from test/test@testdb1 to mouse/mouse@testdb2 replace new_t using select * from t;


Copy Command
The SQL*Plus COPY command can copy data between two databases via SQL*Net .  The preferred method of doing this is to use SQL*Plus on the host where the database resides.  If performing the copy command from a client SQL*Net connection, the data is transferred through the client machine.

The copy command copies data from one Oracle instance to another.   The data is simply copied directly from a source to a target.  The format of the copy command is:

COPY FROM database TO database action -  destination_table (column_name, column_name...) USING query

The action can include:

1) create – If the destination table already exists, copy will report an error, otherwise the table is created and the data is copied. 

2) replace – If the destination table exists, copy will drop and recreate the table with the newly copied data. Otherwise, it will create the table and populate it with the data. 

3) insert – If the destination table exists, copy inserts the new rows into the table. Otherwise, copy reports an error and aborts.

4) append– Inserts the data into the table if it exists, otherwise it will create the table and then insert the data. 


 
#可以设置的参数
Once the command above is executed, the copy utility displays the values of three parameters, each of which can be set with the SQL*Plus set command. 
The arraysize specifies the number of rows that SQL*Plus will retrieve from the database at one time. 
The copycommit parameter specifies how often a commit is performed and is related to the number of trips – one trip is the number of rows defined in arraysize. 
The long parameter displays the maximum number of characters copied for each column with a LONG datatype.


#设置不同的列名
The command above did not specify column names for the new table (new_t).  As a result, the new table will have the same column names as the table being copied.  If different column names are required, they can be specified after the table name:

SQL>copy from test/test@testdb1 to mouse/mouse@testdb2 create new_t using(col1,col2,col3,....) select * from t;

However, if one column name is specified, they all must be specified. 

A DBA could perform. this same function with a database link from one database pointing to another.  The appeal of the copy command is that it only requires SQL*Net service names and proper privileges to get the job done.  For those environments that restrict the usage of database links, the copy utility can be leveraged.  In addition, the copy command provides many options, as defined by the actions create, replace, insert and append. 

If the copy command is executed from a client PC to copy data from remote database DB0 to remote database DB1, the data will be copied from DB0 to the client PC and then to DB1.  For this reason, it is best to use SQL*Plus from either remote host and not require the data to travel through a client machine in order to reach its final destination.

参考文档<>

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10248702/viewspace-704339/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10248702/viewspace-704339/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值