select t.name into v_name from emp t where t.id='555';
如果emp表中没有id为555的记录,就会报ORA-01403 no data found错误。
select into 也就是隐式游标,如果查不到数据返回null的数组,也就是没有一条数据,空记录。
解决方法:
首先了解一下空记录和空值
空记录:返回一行记录,但是里面的值都为null;
空值:返回的是null,也就是没有一条记录返回;
1,用聚合函数修饰:如果查不到数据的话会返回一条空记录。
如:
select max(t.name) into v_name from emp t where t.id='555';
2,使用显示游标处理异常即可。