我有一个功能,我用它给我年初至今的总数。
它需要一个会计期间变量(in_period)和十二个金额。
我记录了帐户期间+ 1与金额指数和期间的出租人之间的差异,并乘以金额,并添加结果产品。
我可以使用类似的方法来获得一个月吗?
CREATE OR REPLACE FUNCTION get_ytd(in_period IN NUMBER,
bucket_01 IN NUMBER DEFAULT 0,
bucket_02 IN NUMBER DEFAULT 0,
bucket_03 IN NUMBER DEFAULT 0,
bucket_04 IN NUMBER DEFAULT 0,
bucket_05 IN NUMBER DEFAULT 0,
bucket_06 IN NUMBER DEFAULT 0,
bucket_07 IN NUMBER DEFAULT 0,
bucket_08 IN NUMBER DEFAULT 0,
bucket_09 IN NUMBER DEFAULT 0,
bucket_10 IN NUMBER DEFAULT 0,
bucket_11 IN NUMBER DEFAULT 0,
bucket_12 IN NUMBER DEFAULT 0)
RETURN NUMBER IS
RESULT NUMBER;
BEGIN
the_period := in_period + 1;
the_sum := sign(the_period - least(1, the_period)) * bucket_01 +
sign(the_period - least(2, the_period)) * bucket_02 +
sign(the_period - least(3, the_period)) * bucket_03 +
sign(the_period - least(4, the_period)) * bucket_04 +
sign(the_period - least(5, the_period)) * bucket_05 +
sign(the_period - least(6, the_period)) * bucket_06 +
sign(the_period - least(7, the_period)) * bucket_07 +
sign(the_period - least(8, the_period)) * bucket_08 +
sign(the_period - least(9, the_period)) * bucket_09 +
sign(the_period - least(10, the_period)) * bucket_10 +
sign(the_period - least(11, the_period)) * bucket_11 +
sign(the_period - least(12, the_period)) * bucket_12;
RESULT := the_sum;
RETURN(RESULT);
END get_ytd;
答案 0 :(得分:0)
您的意思是获得指定的一个期间的价值,而不是那个期间到期的年份?为什么不呢?
return decode(in_period,1,bucket_01,2,bucket_02,3,bucket_03, ... etc);
return (1 - sign(abs(in_period - 1))) * bucket_01 +
(1 - sign(abs(in_period - 2))) * bucket_02 +
(1 - sign(abs(in_period - 3))) * bucket_03 + ...