user2907032
user2907032

Reputation: 467

Convert decimal to hex with leading zeros using oracle

I Wanted to convert 00017 to hex using oracle with leading zero's:

For Example:

**SELECT TO_CHAR(00017,'XXXX') FROM DUAL;**

Current Output of above query 11

But Expected output is with leading zero 00011.

Upvotes: 2

Views: 2806

Answers (1)

derpirscher
derpirscher

Reputation: 17382

For padding zeros you have to add them to the pattern

select to_char(17, '0000X') from dual

In 000X the X is the format specifier and the number of 0 determine the length.

Upvotes: 3

Related Questions