使用背景:
常規進行數據表備份/轉移時,我們通常使用:
Create new_table as select * from old_table
但當是table中包含long類型數據時將無法使用(報錯如下);可用exp/imp或者copy指令代替:
ORA-00997: 非法使用 LONG 數據類型
COPY指令解釋:
COPY {FROM database | TO database | FROM database TO database}
{APPEND|CREATE|INSERT|REPLACE}
destination_table [(column, column, column, ...)]
USING query
操作示例:
命令行輸入sqlplus /nolog 進入SQLPLUS,'/nolog'的意思是無需登錄數據庫
sqlplus /nolog
set long 20000 --long字段的最大長度,多餘部分將被截斷
set arraysize 5000
set copycommit 500
copy from old_user/old_password@old_db to new_user/new_passsword@new_db insert new_user.new_table using SELECT * FROM old_user.old_table where ...
{APPEND|CREATE|INSERT|REPLACE} – 聲明操作數據的方式,下面分別解釋一下:
Append – 向已有的目標表中追加記錄,如果目標表不存在,自動創建,這種情況下和Create等效。
Create – 創建目標表並且向其中追加記錄,如果目標表已經存在,則會返回錯誤。
Insert – 向已有的目標表中插入記錄,與Append不同的是,如果目標表不存在,不自動創建而是返回錯誤。
Replace – 用查詢出來的數據覆蓋已有的目標表中的數據,如果目標表不存在,自動創建。
輸出如下:
數組提取/綁定大小爲 5000。(數組大小爲 5000)
將在每 500 個數組綁定之後提交。(提交的副本爲 500)
最大 long 大小爲 20000。(long 爲 20000)
8471496 行選自 old_user@old_db。
8471496 行已插入 new_user.new_table。
8471496 行已提交至 new_user.new_table (位於 new_user@new_db)。