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: casting into hex?

Re: casting into hex?

From: Jusung Yang <JusungYang_at_yahoo.com>
Date: 6 Feb 2003 13:44:40 -0800
Message-ID: <130ba93a.0302061344.391dfdd9@posting.google.com>


Any reasons why you are doing this? Technically you can do it. But the end results may not be what you expected. You can map each character to its corresponding ASCII value, convert it to hex and then convert the combined character string into raw. Take this example:

SQL> desc t2

 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------
 C1                                                 VARCHAR2(5)

SQL> desc tyu
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------
 C1                                                 RAW(5)

SQL> SQL> select * from t2;

C1



aaksh

SQL> insert into tyu select
hextoraw(to_hex(ascii(substr(c1,1,1)))||to_hex(ascii(substr(c1,2,1)))||   2 to_hex(ascii(substr(c1,3,1)))||to_hex(ascii(substr(c1,4,1)))||to_hex(ascii(substr(c1,5,1 ))))
  3 from t2;

1 row created.

SQL> SQL> select * from tyu;

C1



61616B7368

SQL> so 5-byte varchar2 data is now stored in a RAW(5) table. A lot of conversion effort to get it in, will take similar effort to get it out when you run queries against the raw data field.

"Aakash Bordia" <a_bordia_at_hotmail.com> wrote in message news:<b1sb68$15u$1_at_hanover.torolab.ibm.com>...
> how about strings like "aakash" instead of "abc". That does not work. Thats
> why my question of how to go from char to hex?
> Thanks
>
> "Sybrand Bakker" <gooiditweg_at_nospam.demon.nl> wrote in message
> news:40134vk7287tltlabel4k1dletprjnfis5_at_4ax.com...
> > On Wed, 5 Feb 2003 11:07:10 -0800, "Aakash Bordia"
> > <a_bordia_at_hotmail.com> wrote:
> >
> > >Hello, How can I cast a string like 'abc' to hex and insert it into a raw
> > >column.
> > >
> > >eg: insert into table1 select raw(hex('abc')) from table2
> > >
> > >How do I accomplish this in SQL ?
> > >
> > >I cannot use procedural SQL here.
> > >Thanks
> > >Aakash
> > >
> >
> > The functions are rawtohex and hextoraw
> >
> >
> > Sybrand Bakker, Senior Oracle DBA
> >
> > To reply remove -verwijderdit from my e-mail address
Received on Thu Feb 06 2003 - 15:44:40 CST

Original text of this message

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