Is there a way to copy BLOB records between databases in Oracle 10g?

青春壹個敷衍的年華 提交于 2019-12-05 09:11:58
Datajam

Unfortunately you cannot copy BLOB values using the COPY command.

An alternative is to set up a DB link on the source database, and execute a SQL INSERT statement:

CREATE DATABASE LINK link_to_prod CONNECT TO prod_user IDENTIFIED BY prod_password USING 'prod_db';

INSERT INTO TABLE_A@link_to_prod (COL1, COL2, COL3, BLOB_COL) SELECT COL1, COL2, COL3, BLOB_COL FROM TABLE_A

Oracle's Data Pump (started 10g+) supports moving BLOB data.

John

I came up with a solution I like--this version has a 4000 character limitation on the CLOB.

1) on the COPY TO database:

create TABLE_A_TMP as 
select COL1, COL2, COL3, cast(BLOB_COL as varchar2(4000)) BLOB_COL
from TABLE_A
where 1=0;

2) then run the copy command

COPY FROM user/password@prod_db TO user/password@dev_db -
 INSERT TABLE_A_TMP (COL1, COL2, COL3, BLOB_COL) USING -
 SELECT COL1, COL2, COL3, cast(BLOB_COL as varchar2(4000)) -
 FROM TABLE_A WHERE COL1='KEY' 

3) on the COPY TO database:

INSERT TABLE_A (COL1, COL2, COL3, BLOB_COL)
SELECT COL1, COL2, COL3, BLOB_COL
FROM TABLE_A_TMP

4) then drop the tmp table

I had been struggling with this limitation, and this solution has helped me alot.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!