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: Bill Lucas <Homebrew42_at_hotmail.com>
Date: Wed, 26 Feb 2003 14:32:18 GMT
Message-ID: <Sd47a.16027$jR3.8209359@news1.news.adelphia.net>


"Vladimir M. Zakharychev" <bob_at_dpsp-yes.com> wrote in message news:b3ig1v$cq$1_at_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_at_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.
>

Thanks Vladimir,

I appreciate the information. Still learning the internal workings of Oracle. I did solve the problem earlier today. It wasn't so much with the Conversion as with the extraction from the XML. In the xpath search, I forgot to include the text() so I was getting the XML fragment, which could not be converted to RAW for obvious reasons.

I have changed the function to demonstrate the explicit conversion for clarity as you suggested. That was the same reason I was trying to put it in there before.

Thanks again for the post things are clearing up by the day.

Regards,
Bill Received on Wed Feb 26 2003 - 08:32:18 CST

Original text of this message

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