Oracle: BLOB データを含むテーブルをプレーンテキスト .sql でエクスポート/ダンプする方法は?

Oracle: BLOB データを含むテーブルをプレーンテキスト .sql でエクスポート/ダンプする方法は?

テーブルの 1 つに BLOB フィールドがあるデータベースをダンプしようとしています。

SQL Developer と toad を試しましたが、いずれも PHPMyAdmin のようなバイナリ データを含む「挿入」を生成できませんでした。

これを行う方法やツールはありますか?

前もって感謝します !

答え1

CLOB 列を含むテーブルを SQL スクリプトにエクスポートすると、いくつかの問題が発生します。

  • SQL DeveloperはCLOBではない列のみをエクスポートし、ローダーまたはPDFエクスポートでのみこれをサポートします。
  • Oracle では、char 定数は 4000 文字を超えることができないという制限があります。

Ask TOMの記事 CLOB列を含むテーブルをエクスポートする/*insert*/2017 からは、スクリプトに コメントを入れると 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('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|| 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

これを行う 1 つの方法は、各 BLOB をデータファイルにエクスポートし、SQL ローダーまたは同様のツールを使用して個々のファイルをロードすることです。データをエクスポートするにはカスタム 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 では、データ ポンプは BLOB をエクスポートしますが、何らかの理由でデータ ポンプがオプションではないと想定しています。

関連情報