Convert hexadecimals to decimals in Oracle SQL

1124455 pts.
Tags:
Oracle
SQL
For Oracle SQL, can I convert hexadecimals to decimals (and possibly back again if need be)? I appreciate the help available.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Thanks for coming to ITKE.

You can use the ‘x’ format element.  If you want to convert from hexa to decimal, you use the TO_NUMBER function:

SELECT to_number( 'f', 'x' )
FROM dual;

And if you want to convert from decimal to hexa, you use the TO_CHAR function:

SELECT TO_CHAR(15, 'x' )
FROM dual;

The number of ‘x’ you use defines the number of chars in the hexa value, so make sure to provide enough ‘x’ to cover all the possible values you plan to convert.

To_char adds a leading blank space (reserved in case it needs to add a – sign for negative numbers).  If you don’t want that leading blank, you can combine the ‘fm’ format element, this way:

SELECT TO_CHAR(15, 'fmx' )
FROM dual;

 

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: