Oracle:如何在纯文本 .sql 中导出/转储包含 blob 数据的表?

Oracle:如何在纯文本 .sql 中导出/转储包含 blob 数据的表?

我正在尝试转储一个数据库,该数据库的一个表中包含 BLOB 字段。

我尝试了 SQL Developer 和 toad,但它们都无法生成包括二进制数据(例如 PHPMyAdmin)在内的“插入”。

有什么方法或工具可以做到这一点吗?

提前致谢 !

答案1

将包含 CLOB 列的表导出到 SQL 脚本时,会遇到几个问题:

  • SQL Developer 仅导出非 CLOB 的列,仅支持加载器或 PDF 导出
  • Oracle 中的限制是 char 常量不能大于 4000 个字符。

询问 TOM 文章 导出包含 CLOB 列的表 从 2017 年开始包含一个解决方案,使用将注释放在/*insert*/脚本中将导致 SQL Developer 创建 INSERT 语句的功能。

以下代码将创建一个带有 CLOB 的表并导出到文件 ins.sql

drop table t purge;
create table t (x int, c clob);
declare 
  l varchar2(32000) := lpad('aaaaaa', 5000, 'x');
begin
  insert into t values (1, l);
end;
/

set long 100000
set lines 1000
spool c:\temp\ins.sql
select /*insert*/* from t;
spool off

运行该文件ins.sql将如下所示:

SQL> select /*insert*/* from t;

REM INSERTING into t
SET DEFINE OFF;
Insert into "t" (X,C) values (1,TO_CLOB('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|| TO_CLOB('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaa'));

Elapsed: 00:00:00.488
SQL> spool off

(如果不使用 Oracle,我无法测试该代码。)

答案2

MySQL WorkBench / mysqldump 有一个 --hexblob 选项,可以在这里提供帮助。

https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_hex-blob

答案3

一种方法是将每个单独的 blob 导出到数据文件中,然后使用 sql 加载器或类似工具加载单个文件。您需要编写自定义 sql 脚本来导出数据,但导入相当简单。

在 sql loader 中,控制文件会有如下内容:OPTIONS(skip=1)LOAD DATA CHARACTERSET 'WE8ISO8859P15' INFILE 'images.txt' APPEND INTO TABLE IMAGES FIELDS TERMINATED BY '\t' TRAILING NULLCOLS(NAME,lob_file_data FILLER,DATA LOBFILE(lob_file_data) TERMINATED BY EOF)

在 oracle 中,数据泵将导出 blob,但我认为由于某种原因数据泵不是一个选项。

相关内容