如下:
BEGIN SELECT name into v_name FROM t_student WHERE id = '101' EXCEPTION WHEN NO_DATA_FOUND THEN v_name := ''; END;
这样,就不用提前先select count(1) from t_student where id = ‘101‘;进行判断是否为空了。
上面的捕获异常只会处理没有数据时的错误,如果多于一条的错误,可以再用OTHERS进行捕获
BEGIN SELECT name into v_name FROM t_student WHERE id = '101' EXCEPTION WHEN NO_DATA_FOUND THEN v_name := ''; WHEN OTHERS THEN v_name := '多于一条啦'; END;
时间: 2024-10-09 22:26:13