create or replace function getsal
(
v_job emptype.etype%type
)
return number
as
cursor c_emp is select salary from emptype where etype = v_job;
v_emp c_emp%rowtype;
v_sal emptype.salary%type := 0;
v_sal_sum emptype.salary%type;
begin
open c_emp;
loop
fetch c_emp into v_emp;
exit when c_emp%notfound;
v_sal := v_sal +v_emp.salary;
end loop;
select sum(salary) into v_sal_sum from emptype;
v_sal := v_sal/v_sal_sum;
return v_sal;
end getsal;
/
variable per number;
execute :per:=getsal('CLERK');
print per;
以上代码中注意以下2行:
v_sal emptype.salary%type := 0;
v_sal_sum emptype.salary%type;
该例子是我从书上看的,
为什么v_sal需要初始化为0而v_sal_sum不需要?
我试过如果v_sal不初始化为0,则per值不会有输出,求解释原因