我想(添加p.L_VALUE
和p.I_VALUE
并且使用此结果,减去c.con_value
)将一列减去另一列中的另一列,下面的函数成功编译但是减法结果不正确:
function CF_OP_QTYFormula return Number is
V_QTY number(10);
begin
select sum(nvl(p.L_QTY, 0)) + sum(nvl(p.I_QTY, 0)) - sum(nvl(c.CON_QTY,0))
into V_QTY
from raw_purchase p, raw_consum c
where p.ITEMCODE = c.ITEMCODE
and p.ITEMCODE = :ITEMCODE
and p.MONTH_YEAR between '31-MAY-2010'
and ADD_MONTHS(:date1, -1);
return v_qty;
exception when no_data_found then return null;
end;
答案 0 :(得分:0)
请试试这个:
function CF_OP_QTYFormula( i_ITEMCODE raw_purchase.ITEMCODE%type, i_date1 date ) return Number is
V_QTY number(10);
begin
select sum(nvl(p.L_QTY, 0) + nvl(p.I_QTY, 0) - nvl(c.CON_QTY,0))
into V_QTY
from raw_purchase p, raw_consum c
where p.ITEMCODE = c.ITEMCODE
and p.ITEMCODE = i_ITEMCODE
and p.MONTH_YEAR between to_date('31.05.2010','dd.mm.rrrr') and ADD_MONTHS(i_date1, -1);
return v_qty;
exception when no_data_found then return null;
end;