0

I'm using Oracle APEX to build an application, and I've came to a stage where I need to derive an RGB value from the Hex value generated by the color picker component.

I've tried to look for some documentation referencing any methods to do this conversion but I've not yet had any luck.

Is there any easy way of doing this?

Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
Halfpint
  • 3,967
  • 9
  • 50
  • 92
  • 1
    This is probably the sort of thing you need. http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb – Scott Dec 03 '14 at 05:20

1 Answers1

3

To convert a hexadecimal value to a number use the to_number function with the appropriate format string. For hexadecimal that is an 'x'.

select to_number('AA','xx') from dual

170

Now if your color picker returns a value such as FFEEDD for red, green and blue you will have to get the individual parts of that value and convert them to number. You can use substring for that.

substr('FFEEDD',1,2) -- red value
substr('FFEEDD',3,2) -- green value
substr('FFEEDD',5,2) -- blue value.

Convert these values to number.

select to_number(substr('FFEEDD',1,2),'xx') from dual

255

select to_number(substr('FFEEDD',3,2),'xx') from dual

238

select to_number(substr('FFEEDD',5,2),'xx') from dual

211

Put is all in a function and your done.

Rene
  • 10,391
  • 5
  • 33
  • 46