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('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|| 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 載入器中,控制檔案的內容如下: OPTIONS (skip=1) LOAD DATA CHARACTERSET 'WE8ISO8859P15' INFILE 'images.txt' APPEND INTO TABLE IMAGES FIELDS TERMINATED BY '\t' TRAEND INTO TABLE IMAGES FIELDS TERMINATED BY '\t' TRAEND INTO TABLE IMAGES FIELDS TERMINATED BY '\t' TRAENDILING NULLD N. LOBFILE(lob_file_data) 由EOF 終止)

在 Oracle 中,資料泵將匯出 blob,但我假設由於某種原因資料泵不是選項。

相關內容