BLOBs ins Dateisystem "entladen" - nur mit einer "SQL Abfrage"
Wolltet Ihr schonmal eine Tabelle mit BLOBs in ein Verzeichnis "ausladen" ... wobei jeder BLOB
in eine eigene Datei geschrieben werden soll ...?
Bei mir war es heute wieder mal soweit ... und natürlich hätte man dazu ein wenig PL/SQL-Code mit UTL_FILE schreiben können - ich wollte es aber schnell haben. Also habe ich mein Package für Betriebssystem-Kommandos und Dateisystem-Zugriffe genommen. Meine Tabelle sah so aus ...
SQL> desc target_table Name Null? Typ ----------------------------------------- -------- ------------------------ ID NUMBER FILENAME VARCHAR2(4000) FILECONTENT BLOB
Das "Entladen" konnte ich mit einem einfachen SQL SELECT machen:
SQL> select
2 filename,
3 file_pkg.get_file('/home/oracle/test/'||filename).make_file().append_to_file(filecontent) bytes_written
4 from target_table;
FILENAME BYTES_WRITTEN
-------------------------------------------------- -------------
2010-003a_yahoo_quote.html 3305
2010-003b-bestdbproject.html 1433
2010-007_charset_nls_iana.html 3125
2010-009_emalert_rss.html 17047
2010-009_emalert_rss_01.png 171007
2010-009_emalert_rss_02.png 38661
2010-009_emalert_rss_03.png 141388
2010-010_blob-remote.html 14636
2010-011_imp_dataonly.html 3471
2010-012_recursive-table-functions.html 4916
2010-013_romannumber.html 1153
2010-014-doag-sig-spatial.html 1025
2010-015-dbms-applicationinfo.html 7539
2010-016-addmonths.html 3842
2010-017-zip.html 29251
: :
50 rows selected.
Elaped: 00:00:00.17
Danach sah das Verzeichnis /home/oracle/test so aus ...
[oracle@sccloud038 test]$ ls -lah total 752K drwxr-xr-x 2 oracle oinstall 4.0K Feb 23 13:13 . drwxr-xr-x 3 oracle oinstall 4.0K Feb 23 13:12 .. -rw-r--r-- 1 oracle oinstall 2.8K Feb 23 13:13 2010-001a_apex-plugins.html -rw-r--r-- 1 oracle oinstall 8.9K Feb 23 13:13 2010-001_dbms_datapump_exp.html -rw-r--r-- 1 oracle oinstall 3.6K Feb 23 13:13 2010-002a_oscomm_0.9.html -rw-r--r-- 1 oracle oinstall 8.0K Feb 23 13:13 2010-002_dbms_datapump_imp.html -rw-r--r-- 1 oracle oinstall 3.3K Feb 23 13:13 2010-003a_yahoo_quote.html -rw-r--r-- 1 oracle oinstall 1.4K Feb 23 13:13 2010-003b-bestdbproject.html -rw-r--r-- 1 oracle oinstall 12K Feb 23 13:13 2010-003_dbms_stat_funcs.html -rw-r--r-- 1 oracle oinstall 7.7K Feb 23 13:13 2010-004_miniskript_lo.html -rw-r--r-- 1 oracle oinstall 11K Feb 23 13:13 2010-005_resumable.html -rw-r--r-- 1 oracle oinstall 6.5K Feb 23 13:13 2010-006_video.html -rw-r--r-- 1 oracle oinstall 3.1K Feb 23 13:13 2010-007_charset_nls_iana.html -rw-r--r-- 1 oracle oinstall 29K Feb 23 13:13 2010-008-recursive_with.html -rw-r--r-- 1 oracle oinstall 167K Feb 23 13:13 2010-009_emalert_rss_01.png
Ist doch nett, oder ...? Alles im allem habe ich für das Schreiben dieses Postings mehr Zeit gebraucht ...