I just discovered that if you have a SELECT INTO that raises a TOO_MANY_ROWS exception, the variable still gets assigned the value from the first record the query retrieved. Is that expected behavior?
Here's my example:
for co in my_cursor loop
l_sco_db_id := null;
begin
select db_id
into l_sco_db_id
from objects_tab
where object_name = co.object_name;
exception
when no_data_found then
dbms_output.put_line('No objects_tab record found for Object ' || co.object_name);
when too_many_rows then
dbms_output.put_line('Multiple objects_tab records found for Object ' || co.object_name);
l_sco_db_id := null;
end;
end loop;
This is inside a loop, so I set the variable null at the beginning to ensure it's blank, but I had to explicitly do it again in the WHEN TOO_MANY_ROWS exception, which I didn't expect. None of my coworkers (at least, those in immediate earshot) expected the variable to have a value, either.