我的数据库中有一个大表,我需要更新内部调用的“ColorByte”字段.此字段根据RGB值计算,主要由Excel-VBA Skripts使用,但也在WinForms C#应用程序中使用.它表示一个表示特定颜色的整数值.
这在VBA中起作用如下(没有工作代码只是为了澄清):
r = 5 g = 50 b = 200 colorByte = RGB(r,g,b)
现在我得到了一个复杂的计算方案,用于从公司特定数据中提出更好的RGB值,由我们的研究团队成员在VBA中开发.我必须在数据库上定义这个计算,以便轻松更新我的大表并更正“colorByte”字段.确切的计算并不重要,因为这些东西有效但是:
解决方法
不,没有Oracle内置的RGB()函数,但
formula非常简单
colorByte = red + (green * 256) + (blue * 256 * 256)
所以函数可能看起来像这样
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;
测试用例:
select rgb(5,50,200) as color_value from dual COLOR_VALUE ----------- 13120005 1 row selected.