I have a big table in my database where I need to update the internally called "ColorByte"
field. This field is calculated from RGB values and primarly used by Excel-VBA Skripts but also in WinForms C# Applications. It represents one integer value which represents a specific color.
This works as following in VBA (no working code just for clarification):
r = 5
g = 50
b = 200
colorByte = RGB(r,g,b)
Read more about the RGB-Function here.
Now I got a complex calculation scheme for becomming better RGB-Values out of our company specific data, developed in VBA by a member from our research-team. I have to define this calcution on database to easy update my big table and correct the "colorByte"
field. The exact calculations are unimportant because this stuff works but:
Is there an equivalent of VBA RGB(r, g, b)
Function which I can use in PL/SQL to complete my function?
Or does someone know what this function internally does, so that I can redefine it in PL/SQL?
I think RGB(r,g,b)
simply does
RGB(r,g,b) = 256 * 256 * r + 256 * g + b
Perhaps it is the other way around (i.e. r + 256*g + 256*256*b
) but it I am sure you can find this out by simple try-and-error.
It should be no problem to rebuild this in PL/SQL.
No, there is no Oracle built-in RGB(
) function, but the formula is quite simple
colorByte = red + (green * 256) + (blue * 256 * 256)
So the function might look like this
create or replace function rgb(
p_red in number,
p_green in number,
p_blue in number
) return number
is
begin
return p_red + (p_green * 256) + (p_blue * 256 * 256);
end;
Test case:
select rgb(5, 50, 200) as color_value
from dual
COLOR_VALUE
-----------
13120005
1 row selected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With