日期:2014-05-17  浏览次数:20939 次

oracle找不到数据 问题的解决
select D into C from qyjbxx where A=B; 当在没有满足A=B时 oracle报错 (1403 未找到任何数据)
  D 为 number类型 
  我现在想找到不数据能不能不让它报错,提示条消息就行了。我百度了下好像oracle中也有类似java的异常捕获,
  select D into C from qyjbxx where A=B; 
  exception 
  when no_data_found then 
  Err.oi_errcode := -1;
  Err.oc_errtext := 'XXXX';
  return;
 不能通过编译 好像 select语句下不能接exception 
哪位高手有什么好的方法!谢谢了

------解决方案--------------------
SQL code

begin

select D into C from qyjbxx where A=B;  
  exception  
  when no_data_found then  
  Err.oi_errcode := -1;
  Err.oc_errtext := 'XXXX';
  return;
end;

------解决方案--------------------
plsql的基本单元就是plsql程序块

begin
exception
end;
这就是一个块。

探讨

引用:
SQL code


begin

select D into C from qyjbxx where A=B;
exception
when no_data_found then
Err.oi_errcode := -1;
Err.oc_errtext := 'XXXX';
return;
end;

应该我原来的sel……