Oracle: Как экспортировать/сделать дамп таблицы с данными BLOB-объектов в текстовом формате .sql?

Oracle: Как экспортировать/сделать дамп таблицы с данными BLOB-объектов в текстовом формате .sql?

Я пытаюсь создать дамп базы данных, в одной из таблиц которой есть поле BLOB.

Я пробовал SQL Developer и Toad, но ни один из них не смог сгенерировать «вставку в», включая двоичные данные, как, например, PHPMyAdmin.

Есть ли какой-нибудь способ или инструмент для этого?

Заранее спасибо !

решение1

При экспорте таблицы, содержащей столбец CLOB, в скрипт SQL возникает несколько проблем:

  • SQL Developer экспортирует только столбцы, которые не являются CLOB, поддерживая это только для экспорта загрузчика или PDF.
  • Ограничение в Oracle: константа типа char не может быть длиннее 4000 символов.

Статья «Спросите ТОМА» Экспорт таблицы, содержащей столбец 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('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|| 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 loader или аналогичный инструмент для загрузки отдельных файлов. Вам нужно будет написать собственный скрипт sql для экспорта данных, но импорт будет довольно простым.

В загрузчике SQL управляющий файл будет иметь примерно следующее содержимое: 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 datapump экспортирует BLOB-объекты, но я предполагаю, что по какой-то причине datapump не является вариантом.

Связанный контент