Is it possible to return null from an oracle function?
I have the following oracle function:
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;
When the select statement returns zero rows, it raises the following exception:
ora-01403: no data found.
In this case I would like that the function returns 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;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With