1.场景
查询student表,学号为123456的学生姓名,并赋值给变量v_name
select sname into v_name from student where sno='1';
系统提示
no data found
报错原因:
不存在学号为1的学生,故SELECT语句返回结果为空,无法对变量赋值
2.解决方法
begin
select sname into v_name from student where sno='1';
--捕获异常
exception when no_data_found then v_name:='';
end;