When you execute an implicit implicit cursor in PL / SQL (this is what you did with your SELECT ... INTO ... ), you should remember that it expects at least 1 row and no more than 1 row.
If you get less or more than 1 row, you will get an exception - either NO_DATA_FOUND or TOO_MANY_ROWS, both of which are pretty clear.
If you want the code to do something if an exception occurs, you will have to handle these exceptions.
For instance:
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 when no_data_found then return null; when too_many_rows then return null; end GetAmount;
source share