SELECT INTO 要求有一条返回数据,所以没有返回(NO_DATA_FOUND)或者返回多于一条(TOO_MANY_ROWS)都会抛出异常;
select into 语句嵌入begin ... exception ... end中处理
begin
select e.employeecode,e.employeename
into v_code,v_name
from employee e, empgroup eg
where e.employeeid = eg.employeeid and c1.orgid = eg.orgid
and eg.empgroupid = 100000204;
exception
when no_data_found then
v_code:=null;
v_name:=null;
when others then
v_code:=null;
v_name:='存在相同条件的多条记录啦!';
end;
begin
select e.employeecode,e.employeename
into v_code,v_name
from employee e, empgroup eg
where e.employeeid = eg.employeeid and c1.orgid = eg.orgid
and eg.empgroupid = 100000204 and rownum = 1;
exception
when others then
v_code:=null;
v_name:=null;
end;