首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

如何在存储过程中取不出数据就会出错啊

2012-03-01 
怎么在存储过程中取不出数据就会出错啊?selecttelintov_telfromuserwhereID‘25’执行这句就出错,因为user

怎么在存储过程中取不出数据就会出错啊?
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 ;

热点排行
Bad Request.