Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: substr, substrb and raw datatype
On Tue, 14 Jun 2005 20:34:57 +0200, Rafal Dabrowa interested us by
writing:
> HansF wrote:
>> The Oracle documentation also says: >> [...] >> " >> When Oracle automatically converts RAW or LONG RAW data to and from CHAR >> data, the binary data is represented in hexadecimal form with one >> hexadecimal character representing every four bits of RAW data. For >> example, one byte of RAW data with bits 11001011 is displayed and entered >> as 'CB.' >> "
Again, from the documentation,
"
RAWTOHEX converts raw to a character value containing its hexadecimal
equivalent. The raw argument can be either RAW or BLOB datatype.
"
so we are doing a conversion. Then applying the substrB to the result.
>
> results are the same as for
>
> substr( val, 5, 2)
>
> I'm surprised that such implicit conversion does not take place for
> substrb, although for substr - does. Also, such behavior is
substr does a character-oriented substring. Conversion *must* take place to get a character string.
OTOH, substrb does a byte-oriented substring. As such, I see absolutely no need to convert to any form of character. All you are asking is to hack out something starting at byte 'x'.
Why do you want/expect/hope for a conversion with substrB?
> inconsistent with behavior of length/lengthb function pair.
> Both functions return the same value for raw fields.
Assuming your database/session is set to a single byte character set (and assuming this will influence the results) length() and lengthb() should provide the same result - one character = one byte.
>
>> But, one may ask WHY you are doing character-based substrings of binary >> data? (Rhetorical question <g>)
Why does the 'take the data as a byte-string and don't interpret anything' not work the way you expect?
> I want to know, whether the function behaves really correctly, or
> whether is this an Oracle bug, which may be corrected in future.
In that case, log a TAR. You do have a support contract, don't you??? <g> (After all, you can't expect Oracle to honour anything said here by non-Oracle volunteers.)
-- Hans Forbrich Canada-wide Oracle training and consulting mailto: Fuzzy.GreyBeard_at_gmail.com *** I no longer assist with top-posted newsgroup queries ***Received on Tue Jun 14 2005 - 14:25:17 CDT