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 
哪位高手有什么好的方法!谢谢了

解决方案 »

  1.   


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

  2.   

    应该我原来的select语句外面就有一层 begin end;语句   我刚听了你的在这个select语句外单独加了个begin end,,测试了下好像问题是解决了,能我解释下这是什么原因么,我刚接触存储过程
      

  3.   


    declare
    v_err_code  number;
    v_err_msg varchar2(200);
    begin
    select D into C from qyjbxx where A=B;  
      exception  
      when no_data_found then  
    v_err_code:=sqlcode;
    v_err_msg:=substr(sqlerrm,1,200);
    dbms_output.putline('error  code:'||v_err_code);
    dbms_output.putline('error  message:'||v_err_msg);
      

  4.   

    plsql的基本单元就是plsql程序块begin
    exception
    end;
    这就是一个块。
      

  5.   

    如果在select语句里加个nvl(d,'标志符') 处理不影响你的业务的话,这样就OK了
      

  6.   

    oracle的语法。
    没什么可解释的。