Ich versuche, einen Dump einer Datenbank durchzuführen, bei der eine der Tabellen ein BLOB-Feld enthält.
Ich habe SQL Developer und Toad ausprobiert, aber keiner von ihnen konnte „Insert into“ einschließlich der Binärdaten wie beispielsweise ein PHPMyAdmin generieren.
Gibt es eine Möglichkeit oder ein Tool, dies zu tun?
Dank im Voraus !
Antwort1
Beim Exportieren einer Tabelle, die eine CLOB-Spalte enthält, in ein SQL-Skript treten mehrere Probleme auf:
- SQL Developer exportiert nur Spalten, die keine CLOBs sind, und unterstützt dies nur für Loader- oder PDF-Exporte
- Die Einschränkung in Oracle, dass eine Zeichenkonstante nicht länger als 4000 Zeichen sein kann.
Der Ask TOM-Artikel
Exportieren einer Tabelle, die eine CLOB-Spalte enthält
von 2017 enthält eine Lösung, die die Funktion nutzt, dass das Einfügen des Kommentars /*insert*/
in das Skript SQL Developer dazu veranlasst, INSERT-Anweisungen zu erstellen.
Der folgende Code erstellt eine Tabelle mit einem CLOB und exportiert sie in die Datei
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
Das Ausführen der Datei ins.sql
sieht folgendermaßen aus:
SQL> select /*insert*/* from t;
REM INSERTING into t
SET DEFINE OFF;
Insert into "t" (X,C) values (1,TO_CLOB('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|| TO_CLOB('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaa'));
Elapsed: 00:00:00.488
SQL> spool off
(Da ich kein Oracle verwende, kann ich diesen Code nicht testen.)
Antwort2
MySQL WorkBench / mysqldump haben eine Option --hexblob, die hier helfen könnte.
https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_hex-blob
Antwort3
Eine Möglichkeit hierfür besteht darin, jeden einzelnen Blob in eine Datendatei zu exportieren und dann SQL Loader oder ein ähnliches Tool zum Laden der einzelnen Dateien zu verwenden. Sie müssten ein benutzerdefiniertes SQL-Skript schreiben, um die Daten zu exportieren, aber der Import wäre relativ unkompliziert.
Im SQL Loader hätte die Steuerdatei einen Inhalt wie diesen: 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 )
In Oracle exportiert Datapump Blobs, aber ich gehe davon aus, dass Datapump aus irgendeinem Grund keine Option ist.