Home » SQL & PL/SQL » SQL & PL/SQL » NUMBER to HEX, HEX to NUMBER (Oracle 11gR2, Oracle Linux)
NUMBER to HEX, HEX to NUMBER [message #651083] Tue, 10 May 2016 22:44 Go to next message
madhuridara
Messages: 3
Registered: October 2009
Junior Member
I am trying to convert a number using these functions:

select TO_CHAR(164489235,'XXXXXXXXX') HEX11, RAWTOHEX(UTL_RAW.CAST_TO_RAW(164489235))) HEX1 from dual;
return
HEX11 HEX1
9CDE813 313634343839323335

I am unable to understand why HEX11 and HEX1 return different values.
Could anyone please help me understand the difference between these functions?

When I use the online converters like (https://www.easycalculation.com/hex-converter.php)
to convert back the HEX to decimal value, HEX11 returns the 164489235 back but not HEX1.

Any help is greatly appreciated.

TY!
Re: NUMBER to HEX, HEX to NUMBER [message #651086 is a reply to message #651083] Wed, 11 May 2016 00:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
TO_CHAR display the number as an hexadecimal string.
UTL_RAW.CAST_TO_RAW converts each digit to the character representing it: 1 -> '1' which x31 and RAWTOHEX displays this later as hexadecimal string value: '1' -> 31:
SQL> select ascii('1'), to_char(ascii('1'),'XX') from dual;
ASCII('1') TO_
---------- ---
        49  31

Note you don't need RAWTOHEX in the later query if you use SQL*Plus as this later itself converts a RAW to its hexadecimal representation:
 SQL> select UTL_RAW.CAST_TO_RAW(164489235) from dual;
 UTL_RAW.CAST_TO_RAW(164489235)
 -----------------------------------------------------------
 313634343839323335
(=1 6 4 4 8 9 2 3 5)

Re: NUMBER to HEX, HEX to NUMBER [message #651367 is a reply to message #651086] Mon, 16 May 2016 10:28 Go to previous message
madhuridara
Messages: 3
Registered: October 2009
Junior Member
Thank You so Much!
Previous Topic: oracle session leak
Next Topic: Batch file to run sql script
Goto Forum:
  


Current Time: Fri Apr 26 12:49:52 CDT 2024