Home
Analytics
How to decode a very long BLOB?
higleyjp
<p>Hello there,</p>
<p> </p>
<p>I have gotten a lot of help from reading through posts on this forum before, but I am having some trouble now trying to get data out of a BLOB. I'm using <em>utl_raw.cast_to_varchar2</em> to extract message contents from a blob field in my database. Some of the blobs are longer than 2000 characters, so I added in <em>dbms_lob.substr</em> to only look at 2k char chunks at a time. The first line functions properly and returns the first chunk of data, but when I try to extract the second chunk I receive an error: "ORA-06502: PL/SQL: numeric or value error: raw variable length too long."</p>
<div>
<pre class="_prettyXprint">
utl_raw.cast_to_varchar2( dbms_lob.substr( ma.MSG, 2000, 1 ) ) as MSG1,
utl_raw.cast_to_varchar2( dbms_lob.substr( ma.MSG, 4000, 2001 ) ) as MSG2</pre>
<p>The longest blob which may be returned currently has length of 4155, so I would like to break the message up into 3 chunks to return up to 6000 characters. I have tried making the second line as little as one character (2001-2002) and also isolating just the second chunk, but I still receive the same error.</p>
<p> </p>
<p>Please advise, how can I decode the second (and third) chunks of the blob to get the entire message.</p>
<p> </p>
<p>Thank you!</p>
<p>Justin</p>
</div>
<p> </p>
Find more posts tagged with
Comments
higleyjp
<p>As usual, posting to the forum brought forth a solution immediately. A co-worker pointed out that the second parameter for the <em>substr</em> function is the number of characters to return and NOT the end character position as coded above. Changing line 2 to the following fixed the problem:</p>
<pre class="_prettyXprint">
utl_raw.cast_to_varchar2( dbms_lob.substr( ma.MSG, 2000, 2001 ) ) as MSG2</pre>
<p>-Justin</p>