是否可以从oracle函数返回null?
我有以下oracle函数:
create or replace function vta.GetAmount(p_month NUMBER) return number is v_amount number(9); begin select amount into v_amount from salary where salary.month = p_month; return v_amount; end GetAmount;
当select语句返回零行时,它会引发以下异常:
ora-01403:未找到数据.
在这种情况下,我希望该函数返回null.
解决方法
create or replace function vta.GetAmount(p_month NUMBER) return number is v_amount number(9); begin select amount into v_amount from salary where salary.month = p_month; return v_amount; exception -- code to handle no data when no_data_found then return null; end GetAmount;