简体   繁体   中英

Oracle How to Uncompress Blob

I'm extracting BLOB column from a Oracle table.

Some of the blob values I'm getting are in right string characters.

However some of the blob values are not displaying correct the string. It seems that these rows are "compressed" .

Table Name: TableA
Column Name: ID,                Type: Number
Column Name: BLOB_BINARY_VALUE, Type: BLOB
Column Name: BLOB_COMPRESSED,   Type: Number

Here is the SQL I used:

Select BLOB_BINARY_VALUE FROM TableA WHERE ID =  1234567;

I also tried using:

Select TO_BLOB(BLOB_BIN_VALUE) FROM TableA WHERE ID =  1234567;

Example of Wrong Blob value I'm getting: (I trimmed the value below because of it's length)

 öp‘CÇL.aÜÌIëÉ8gbȨ!ƒ™2fÌÀÌ…mc›cÆÌ:0óÆ
:bØ>n€7iض1M9sÊТÉSДaÃ6gvôéÓ@;iÊÜY“Æ

I'm guessing that this BLOB is in compressed format. How can I uncompressed this kind BLOB?

Thank you very much in advance.

UPDATE 1: Example of Correct Blob query which I'm also expecting from others:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS Shell Dlg;}}
\viewkind4\uc1\pard\f0\fs20 MESSAGE HERE MESSAGE HERE MESSAGE HERE.   \par
}

UPDATE 2:

There is another column in the database named "BLOB_COMPRESSED". The rows that have "0"s are the ones displaying correct values. The rows that have "1"s are the ones displaying wrong values. So I'm guessing that the data is compressed.

UPDATE 3: I tried to follow the advise from this link but still getting like compressed string: How do I get textual contents from BLOB in Oracle SQL

Select utl_raw.cast_to_varchar2(dbms_lob.substr(BLOB_BIN_VALUE)) 
FROM TableA 
WHERE ID = 1234567;

This worked for me :-

select  
utl_raw.cast_to_varchar2( dbms_lob.substr( utl_compress.lz_uncompress(BLOB_BIN_VALUE), 2000, 1) )
 from TableA  where ID = <ID>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM