Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 889
ProfessionalAmateur Avatar asked May 16 '11 20:05

ProfessionalAmateur


People also ask

How do I copy BLOB data?

Using Java to copy a BLOB/LOB to another database You can use getBytes and setBytes to copy BLOBs from one database to another database.

How do I transfer data from one database to another in Oracle?

When copying between Oracle databases, you should use SQL commands (CREATE TABLE AS and INSERT) or you should ensure that your columns have a precision specified. The USING clause specifies a query that names the source table and specifies the data that COPY copies to the destination table.

Is BLOB supported by all databases?

BLOBs can only be stored using the data portion of a key/data pair. They are supported only for Btree, Hash, and Heap databases, and only so long as the database is not configured for checksums, encryption, duplicate records, or duplicate sorted records.


2 Answers

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
like image 178
Datajam Avatar answered Nov 15 '22 00:11

Datajam


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

like image 28
OMG Ponies Avatar answered Nov 14 '22 23:11

OMG Ponies