Is there a way to copy BLOB records between databa

2019-04-28 22:38发布

We have a production table that has millions of rows in it and contains a BLOB field, I would like to copy a smaller selection of these records into our development database without getting a DBA involved if possible. I tried the following COPY command but received a CPY-0012: Datatype cannot be copied

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

Is there a way to copy records with a BLOB field between databases via SQL?

3条回答
叛逆
2楼-- · 2019-04-28 22:48

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
查看更多
女痞
3楼-- · 2019-04-28 22:55

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.

查看更多
在下西门庆
4楼-- · 2019-04-28 22:59

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

查看更多
登录 后发表回答