Re: rawtohex question

From: Vladimir M. Zakharychev <bob_at_dpsp-yes.com>
Date: Wed, 25 Jun 2003 15:37:56 +0400
Message-ID: <bdc1is$eln$1_at_babylon.agtel.net>


"Jan Gelbrich" <j_gelbrich_at_westfalen-blatt.de> wrote in message

news:bdbsfl$rbc8j$1_at_ID-152732.news.dfncis.de...

> "marbo" <marbo_at_tpi.pl> schrieb im Newsbeitrag
> news:bdbol0$f1j$1_at_nemesis.news.tpi.pl...
> > How to do something like this in oracle 8.1 (in 9 it works)
> >
> > i := to_char(rawtohex(abs(dbms_random.random())));
> >
> > I'd like to cenvert Interger in HEX.
> >
>
> select
> to_char(
> rawtohex(
> abs(
> dbms_random.random
> )
> )
> )
> from dual;
>
> TO_CHAR(RAWTOHEX(ABS(DBMS_RANDOM.RANDOM)))
> --------------------------------------------
> C50851172120
>
> What´s the problem ? It worked for me on OEE 8.1.7.3
>

Well, the problem is that this doesn't convert an integer to its hexadecimal representation, it converts the internal representation of the value to hexadecimal:

SQL> select dump(100) from dual;

DUMP(100)



Typ=2 Len=2: 194,2

SQL> select rawtohex(100) from dual;

RAWT



C202

(0xC2 = 194)

You may want to try TO_CHAR(integer,'FM0XXXXXXX'), which works perfectly in 8.1.7+:

SQL> select to_char(100,'FM0XXXXXXX') from dual;

TO_CHAR(1



00000064
-- 
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.
Received on Wed Jun 25 2003 - 13:37:56 CEST

Original text of this message