无论我选择哪个数字,该函数始终返回0
create or replace function FNC_PRICE_AVE_BUY(PRICE_AVE in number)
return number
is
V_AVE number(6,2);
begin
select NVL((avg(AMOUNT_PRICE_BUY)),0) into V_AVE from BUYER
where AMOUNT_PRICE_BUY = PRICE_AVE;
return V_AVE;
end FNC_PRICE_AVE_BUY;
/
set serveroutput on;
select FNC_PRICE_AVEC_BUY(31) as Average_price_321 from dual;
答案 0 :(得分:1)
select AMOUNT_PRICE_BUY from BUYER where AMOUNT_PRICE_BUY = 31;
上面查询的值返回空值,这就是为什么每次都为零的原因
答案 1 :(得分:0)
根据您问题下方的评论2,我认为这是您想要的逻辑:
创建一个返回买家平均价格的函数。
该参数应为买方ID。
返回值是该买家的平均价格。
create or replace function FNC_PRICE_AVE_BUY(BUYER_ID in number)
return number
is
V_AVE number(6,2);
begin
select NVL((avg(AMOUNT_PRICE_BUY)),0) into V_AVE from BUYER
where ID = BUYER_ID;
return V_AVE;
end FNC_PRICE_AVE_BUY;