select tel into v_tel from user where ID=‘25’ ;
执行这句就出错,因为user 里面没有ID=25的数据,我想应该是取出空值啊,怎么就抱错啊?
Error 100: ORA-01403: 未找到数据
------解决方案--------------------
select tel into v_tel from user where ID=‘25’
exception
when no_data_found then
v_tel := '-1 ';
------解决方案--------------------
oracle 就是这样
用异常处理吧
------解决方案--------------------
加上异常处理机制NO_DATA_FOUND
------解决方案--------------------
我一般情况下这样写:
select count(0) into v_temp from user where id = '25 '
if v_temp <> 0 then
select tel into v_tel from user where ID=‘25’;
end if;
当然,你也可以使用上面说的捕捉异常
------解决方案--------------------
begin
select tel into v_tel from user where ID=‘25’;
exception
when no_data_found then
v_tel := '-1 ';
end ;