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('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|| TO_CLOB('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaa'));
Elapsed: 00:00:00.488
SQL> spool off
将包含 CLOB 列的表导出到 SQL 脚本时,会遇到几个问题:
Ask TOM 文章 Exporting a table that contains a CLOB column from 2017 包含一个解决方案,使用
/*insert*/
在脚本中放置注释的功能将导致 SQL Developer 创建 INSERT 语句。以下代码将创建一个带有 CLOB 的表并将其导出到文件
ins.sql
:运行该文件
ins.sql
将如下所示:(不使用 Oracle,我无法测试这段代码。)
MySQL WorkBench / mysqldump 有一个 --hexblob 选项,可以在这里提供帮助。
https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_hex-blob
一种方法是将每个单独的 blob 导出到数据文件中,然后使用 sql loader 或类似工具加载单独的文件。您需要编写自定义 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 , 数据 LOBFILE(lob_file_data) 由 EOF 终止)
在 oracle 中,数据泵将导出 blob,但我假设由于某种原因数据泵不是一个选项。