有没有办法在 Oracle 10g 中的数据库之间复制 BLOB 记录?

发布于 2024-11-07 18:28:06 字数 372 浏览 5 评论 0原文

我们有一个生产表,其中有数百万行并包含 BLOB 字段,我想将这些记录中的一小部分复制到我们的开发数据库中,如果可能的话,无需 DBA 参与。我尝试了以下 COPY 命令,但收到CPY-0012:无法复制数据类型

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' 

有没有办法通过 SQL 在数据库之间复制带有 BLOB 字段的记录?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

dawn曙光 2024-11-14 18:28:06

遗憾的是,您无法使用 COPY 命令复制 BLOB 值。

另一种方法是在源数据库上设置数据库链接,然后执行 SQL INSERT 语句:

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

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
旧瑾黎汐 2024-11-14 18:28:06

Oracle 的数据泵(从 10g+ 开始) 支持移动 BLOB 数据。

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

旧梦荧光笔 2024-11-14 18:28:06

我想出了一个我喜欢的解决方案——这个版本对 CLOB 有 4000 个字符的限制。

1)在复制到数据库上:

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

2)然后运行复制命令

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)在复制到数据库上:

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

4)然后删除tmp表

我一直在努力解决这个限制,这个解决方案对我帮助很大。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文