Probably the best way is to handle no_data_found
begin SELECT column1 INTO local_variable FROM table1 where column2 = p_val; exception when no_data_found then local_variable := null; end;
Also, if you select using the primary key / unique key (which is unique to column2), then there is a trick you can do
SELECT max(column1) INTO local_variable FROM table1 where column2 = p_val;
source share