读书人

Error 100: ORA-01403: 未找到数据,怎

发布时间: 2014-01-28 21:26:46 作者: rapoo

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 ;

        

读书人网 >oracle

热点推荐