create table test(id int primary key, descr varchar(10));
insert into test values (1,'one'),(2,'two'),(3,'three');
delimiter $$
create or replace procedure test_sp(inp_id int)
returns void as
declare
v_descr varchar(10);
begin
begin
select descr into v_descr from test where id = inp_id;
echo select v_descr;
exception
when ER_INTO_VARIABLES_NO_ROWS then
echo select 'No rows found';
end;
end $$
delimiter ;
call test_sp(1); -- returns 'one'
call test_sp(100); -- returns 'No rows found'
如果它在存储过程中,则可以使用
ER_INTO_VARIABLES_NO_ROWS
. 示例如下: