copy在没有dblink下可以处理小额数据的迁移
SQL*Plus Copy Command的语法: COPY {FROM database | TO database | FROM database TO database} {APPEND|CREATE|INSERT|REPLACE} destination_table [(column, column, column, ...)] USING query
{APPEND|CREATE|INSERT|REPLACE} – 声明操作数据的方式,下面分别解释一下: Append – 向已有的目标表中追加记录,如果目标表不存在,自动创建,这种情况下和Create等效。 Create – 创建目标表并且向其中追加记录,如果目标表已经存在,则会返回错误。 Insert – 向已有的目标表中插入记录,与Append不同的是,如果目标表不存在,不自动创建而是返回错误。 Replace – 用查询出来的数据覆盖已有的目标表中的数据,如果目标表不存在,自动创建。
使用过程如下:
C:\Users\Administrator>sqlplus /nolog SQL*Plus: Release 11.2.0.3.0 Production on 星期四 4月 3 15:02:38 2014 Copyright (c) 1982, 2011, Oracle. All rights reserved. --copy table xx2 SQL> copy from copy1/copy1@11gtest to copy2/copy2@11gtest create xx2 using selec t * from xx1; 数组提取/绑定大小为 15。(数组大小为 15) 将在完成时提交。(提交的副本为 0) 最大 long 大小为 80。(long 为 80) 表 XX2 已创建。 75374 行选自 copy1@11gtest。 75374 行已插入 XX2。 75374 行已提交至 XX2 (位于 copy2@11gtest)。 --insert table xx2 SQL> copy from copy1/copy1@11gtest to copy2/copy2@11gtest insert xx2 using selec t * from xx1; 数组提取/绑定大小为 15。(数组大小为 15) 将在完成时提交。(提交的副本为 0) 最大 long 大小为 80。(long 为 80) 75374 行选自 copy1@11gtest。 75374 行已插入 XX2。 75374 行已提交至 XX2 (位于 copy2@11gtest)。 --新建个唯一约束 SQL> copy from copy1/copy1@11gtest to copy2/copy2@11gtest append xx1 using selec t * from xx1; 数组提取/绑定大小为 15。(数组大小为 15) 将在完成时提交。(提交的副本为 0) 最大 long 大小为 80。(long 为 80) ERROR: ORA-00001: 违反唯一约束条件 (COPY2.COPY2_PK) --Replace 重置 SQL> copy from copy1/copy1@11gtest to copy2/copy2@11gtest Replace xx1 using sele ct * from xx1; 数组提取/绑定大小为 15。(数组大小为 15) 将在完成时提交。(提交的副本为 0) 最大 long 大小为 80。(long 为 80) 表 XX1 已删除。 表 XX1 已创建。 1 行选自 copy1@11gtest。 1 行已插入 XX1。 1 行已提交至 XX1 (位于 copy2@11gtest)。