RE: Strange(?) behaviour with utl_raw.cast_to_raw
Date: Tue, 21 Jul 2015 03:25:47 -0400
Message-ID: <18fe01d0c386$78e657a0$6ab306e0$_at_rsiz.com>
LENGTH is LENGTH(char)
When you cast ‘ABC’ to raw and then convert it to char display it is three 2 digit numbers, ergo length returns 6.
Possibly you want vsize .
mwf
From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Steve Baldwin
Sent: Tuesday, July 21, 2015 2:39 AM
To: Jonathan Lewis
Cc: oracle-l_at_freelists.org
Subject: Re: Strange(?) behaviour with utl_raw.cast_to_raw
Is this what you mean?
SQL> select dump(utl_raw.cast_to_raw('abc'), 16) from dual;
DUMP(UTL_RAW.CAST_TO_RAW('ABC'),16)
Typ=23 Len=3: 61,62,63
I think there is something weird with this function - or more likely something I'm not understanding.
For example:
SQL> select utl_raw.cast_to_raw(chr(255)) from dual;
UTL_RAW.CAST_TO_RAW(CHR(255))
FF
Seems reasonable. But:
SQL> set null '<null>'
SQL> select utl_raw.cast_to_raw(chr(255) || chr(255)) from dual;
UTL_RAW.CAST_TO_RAW(CHR(255)||CHR(255))
<null>
Ok. Maybe something to do with an invalid utf8 string. What about converting to an 8-bit char set?
SQL> select utl_raw.cast_to_raw(convert(chr(255) || chr(255), 'WE8ISO8859P1')) from dual;
UTL_RAW.CAST_TO_RAW(CONVERT(CHR(255)||CHR(255),'WE8ISO8859P1'))
<null>
According to the utl_raw docs:
This function converts a VARCHAR2 value represented using some number of data bytes into a RAW value with that number of data bytes. The data itself is not modified in any way, but its data type is recast to a RAW data type.
On Tue, Jul 21, 2015 at 2:34 PM, Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk> wrote:
Try dump(... , 16)
97 = 0x0061 -- 2 bytes
Regards
Jonathan Lewis
Sent from my iPad
On 21 Jul 2015, at 03:38, Steve Baldwin <stbaldwin_at_multiservice.com> wrote:
Is this expected behaviour?
SQL> select length(utl_raw.cast_to_raw('abc')) from dual;
LENGTH(UTL_RAW.CAST_TO_RAW('ABC'))
6
SQL> select dump(utl_raw.cast_to_raw('abc')) from dual;
DUMP(UTL_RAW.CAST_TO_RAW('ABC'))
Typ=23 Len=3: 97,98,99
I was expecting the first select to return a length of 3 - just like the dump in the second select.
(Oracle 11.2.0.4)
Thanks,
Steve
This email is intended solely for the use of the addressee and may contain information that is confidential, proprietary, or both. If you receive this email in error please immediately notify the sender and delete the email..
This email is intended solely for the use of the addressee and may contain information that is confidential, proprietary, or both. If you receive this email in error please immediately notify the sender and delete the email..
-- http://www.freelists.org/webpage/oracle-lReceived on Tue Jul 21 2015 - 09:25:47 CEST