Oracle存储过程function语法及案例

本文介绍了一个PL/SQL函数的创建及使用案例,该函数用于从数据库表sx03_gl_accasst中根据指定条件计算me或mb字段的总和,并返回计算结果。函数通过参数para确定计算哪个字段的总和。
create or replace function F01_SX03_SUM(statdate varchar2,
                                        code     varchar2,
                                        para     varchar2)

 RETURN number IS
  v_me number;
  v_mb number;

begin

  if para = 'me' then
  
    select nvl(sum(nvl(me, 0)), 0) / 10000
      into v_me
      from sx03_gl_accass t
     where t.ccode like (code || '%')
       and t.iyeriod = substr(replace(statdate, '-', ''), 1, 6)
       and t.citem_id in
           (select distinct (ts.citem_id)
              from sx03_gl_accass ts
             where ts.ccode = '4001'
               and ts.me <> 0
               and ts.iyeriod = substr(replace(statdate, '-', ''), 1, 6));
    return v_me;
  
  elsif para = 'mb' then
    select nvl(sum(nvl(mb, 0)), 0) / 10000
      into v_mb
      from sx03_gl_accass t
     where t.ccode like (code || '%')
       and t.iyeriod = substr(statdate, 1, 4) || '01'
       and t.citem_id in
           (select distinct (ts.citem_id)
              from sx03_gl_accass ts
             where ts.ccode = '4001'
               and ts.mb <> 0
               and ts.iyeriod = substr(statdate, 1, 4) || '01');
    return v_mb;
  end if;

end;

转载于:https://www.cnblogs.com/liudi1992/p/3866429.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值