exception 
when no_data_found then
 ....
end;

解决方案 »

  1.   

    select ..into....语句如果 where子句中没有匹配的值
    则会发生异常而不是sql%notfound
    所以捕捉NO_DATA_FOUND异常就可以了
      

  2.   

    to:leborety(那只螃蟹),什么意思?可否详细一点?
      

  3.   

    select ..into....语句如果 where子句中没有匹配的值
    则会发生异常而不是sql%notfound
    所以捕捉NO_DATA_FOUND异常就可以了
      

  4.   

    如果在你的存储过程中必须要下列代码:
    Select visitnum into iCount From MyTable Id = 1;
    If iCount is null Then
       iCount := 0;
    End If
    请你在执行Select visitnum into iCount From MyTable where Id = 1;
    语句前先用下面的语句
    Select count(*) into 整型变量 From MyTable where Id = 1;
    判断表里是否有记录即:Select count(*) into 整型变量 From MyTable where Id = 1;
    if 整型变量>0 then
      Select visitnum into iCount From MyTable Id = 1;
      If iCount is null Then
         iCount := 0;
      End If
    else
      ......
    end if 
      

  5.   

    可是当不存在这样一条记录时,存储过程报错,告诉我那行SQL语句未找到数据!所以要捕获错误!
      

  6.   

    使用例外
    iCount := '';
    begin
        Select visitnum into iCount From MyTable Id = 1;
    Exception 
        When NO_DATA_FOUND then
             If iCount is null Then
                iCount := 0;
              End If;
    end;