ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 写了个累加与累乘的函数包

写了个累加与累乘的函数包

原创 Linux操作系统 作者:木呼 时间:2010-07-20 17:05:56 0 删除 编辑

现在大家计算这么一个公式

每年固定投资1万元,持续投资5年年回报率5%,10年后有多少钱只要

select  select pack_num_totting_up.intt_power(10,1,0.5) from dual

包头

create or replace package pack_num_totting_up as
    ----输入利率以及,年度,得到利滚利的总利率.
    ---- 如年利率5%,投资10年,返回结果为 (1+5%)^10     1.05的10次方。
    function number_power (interest number,years integer)
      return number;
    ---- maxno 投资时间,continue持续支持一定投资时间,返回一个投资列表
    --如 每年投资10000元,持续5年,年回报率5% 10000((1+5%)^10+(1+5%)^9+(1+5%)^8+(1+5%)^7+(1+5%)^6)
    ---返回 10,9,8,7,6
    function number_split (maxno number,continue number)
      return num_split pipelined;
    ----  输入利率,最高年度,持续投资年份,得到总收入
    ---如上所诉 即  ((1+5%)^10+(1+5%)^9+(1+5%)^8+(1+5%)^7+(1+5%)^6) 的值
    function intt_power(maxno in number,
                        continue in number,
                        i     in number)
    return number;
end;

包体

create or replace package body pack_num_totting_up as
    ----输入利率以及,年度,得到利滚利的总利率.
    ---- 如年利率5%,投资10年,返回结果为 (1+5%)^10     1.05的10次方。

    function number_power (interest number,years integer)
    return number
    as
      V_a number:=1;
      V_itt number:=interest;
      V_b number:=1;
    begin
        loop
          exit when V_b> years;
          V_a:= V_a*(1+V_itt);
          V_b:= V_b+1;
        end loop;
        return V_a;
    end number_power;
    ---- maxno 投资时间,continue持续支持一定投资时间,返回一个投资列表
    --如 每年投资10000元,持续5年,年回报率5% 10000((1+5%)^10+(1+5%)^9+(1+5%)^8+(1+5%)^7+(1+5%)^6)
    ---返回 10,9,8,7,6
    ---CREATE OR REPLACE TYPE num_split IS TABLE OF number ;
    function number_split (maxno number,continue number)

    return num_split pipelined
    as
      V_max number:=maxno;
      V_min number:=maxno-continue;
      begin
        while V_max >V_min loop
         pipe row(V_max);
         V_max:=V_max-1;
        end loop;
        return;
      end number_split;
    ----  输入利率,最高年度,持续投资年份,得到总收入
    ---如上所诉 即  ((1+5%)^10+(1+5%)^9+(1+5%)^8+(1+5%)^7+(1+5%)^6) 的值
    function intt_power(maxno in number,
                                          continue in number,
                                           i     in number)
    return number
    as
       c  number:=0;
       a  number;
    begin
       for v1 in (select * from table(number_split(maxno,continue))) loop
            a:=number_power(i,v1.column_value);
            c:=c+a;
       end loop;
       return c;
    end;
end;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23754390/viewspace-668519/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: TNS-12542与MSN
请登录后发表评论 登录
全部评论

注册时间:2010-04-19

  • 博文量
    93
  • 访问量
    169219