Re: Strange(?) behaviour with utl_raw.cast_to_raw

  • From: Steve Baldwin <stbaldwin@xxxxxxxxxxxxxxxx>
  • To: "Mark W. Farnham" <mwf@xxxxxxxx>
  • Date: Tue, 21 Jul 2015 17:40:01 +1000

Thanks Mark. You're correct. I was assuming LENGTH() worked on RAW values
but it must be coalescing the argument to char first.

Thanks to all responders.

Steve

On Tue, Jul 21, 2015 at 5:25 PM, Mark W. Farnham <mwf@xxxxxxxx> wrote:

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@xxxxxxxxxxxxx [mailto:
oracle-l-bounce@xxxxxxxxxxxxx] *On Behalf Of *Steve Baldwin
*Sent:* Tuesday, July 21, 2015 2:39 AM
*To:* Jonathan Lewis
*Cc:* oracle-l@xxxxxxxxxxxxx
*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@xxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxx>
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..

------------------------------------------------------------------



--


------------------------------------------------------------------
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..
------------------------------------------------------------------

Other related posts: