Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: RAW Data From an XML Document

Re: RAW Data From an XML Document

From: Vladimir M. Zakharychev <bob_at_dpsp-yes.com>
Date: Wed, 26 Feb 2003 16:38:32 +0300
Message-ID: <b3ig1v$cq$1@babylon.agtel.net>


"Bill Lucas" <Homebrew42_at_hotmail.com> wrote in message news:qmS6a.15651$jR3.8020001_at_news1.news.adelphia.net...

> SELECT UTL_Raw.cast_to_raw('1') FROM Dual; yeilds 31

Right, because Oracle implicitly calls RAWTOHEX() function to convert your RAW back to VARCHAR2 for display. If you'd query as

SELECT UTL_Raw.cast_to_varchar2(UTL_Raw.cast_to_raw('1')) FROM Dual;

you'd get expected result - 1. 31 is hexadecimal representation of the ASCII code for '1'. And yes, UTL_RAW.CAST_TO_xxx simply changes the data type for the argument while preserving the value, it can't be used for hex-to-raw-and-back translation. There are HEXTORAW() and RAWTOHEX() built-in functions for this (and your test query is an example of their implicit use.)

>What I need to do is get the GUID data from the XML document and into a
>raw(16) variable exactly as it came in from the document..
>
>So If the XML Fragment looked like this
>
><Equipment>
> <IsChanged>9CF8D265824146D7A43466B385A55CE8</IsChanged>
></Equipment>
>
>How could I get the '9CF8D265824146D7A43466B385A55CE8' into a raw(16)
>datatype so I can use it in stored procedures?

If I understand your requirement correctly, you want that hexadecimal string to be decoded into raw data it represents (bytes 0x9c, 0xf8, ...) Well, that's pretty easy:

rwGUID := xmlFrag.getStringVal;

That simple. Since rwGUID's type is (hopefully) RAW, Oracle will implicitly call HEXTORAW() on assignment and will convert your hexadecimal GUID string into raw bytes. An explicit call to HEXTORAW() is recommended though:

rwGUID := HEXTORAW(xmlFrag.getStringVal);

to make things clearer and avoid implicit (and thus obscure) conversions.

Hope this helps. Corrections and additions welcome.

--
Vladimir Zakharychev (bob@dpsp-yes.com)                http://www.dpsp-yes.com
Dynamic PSP(tm) - the first true RAD toolkit for Oracle-based internet applications.
All opinions are mine and do not necessarily go in line with those of my employer.
Received on Wed Feb 26 2003 - 07:38:32 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US