select id into v_id from test; 如果记录有多条或者没有记录都会报异常 改成: select count(id) into v_id from test where ....; 这样不管有没有合条件的记录,都不会抛异常 接下来可以这样判断 if v_id = 0 then --没有记录 ... else ... end if
先用select count(*) into num from test; 然后判断num是否为零。 这样能满足要求,不知是否是你想要的?
DECLARE v_id varchar(10); begin select id into v_id from test; commit; exception when no_data_found then Dbms_Output.put_line('no result'); when too_many_rows then Dbms_Output.put_line('multi result'); end;
如果记录有多条或者没有记录都会报异常
改成:
select count(id) into v_id from test where ....;
这样不管有没有合条件的记录,都不会抛异常
接下来可以这样判断
if v_id = 0 then --没有记录
...
else
...
end if
然后判断num是否为零。
这样能满足要求,不知是否是你想要的?
v_id varchar(10);
begin
select id into v_id from test;
commit;
exception
when no_data_found then
Dbms_Output.put_line('no result');
when too_many_rows then
Dbms_Output.put_line('multi result');
end;