0
悬赏园豆:100 [待解决问题] 浏览: 12次我向 变量 num1 赋值
select  AFG_ISUSED into num1 from app_config ac where ac.afg_key = '01';
但是 app_config 表里面没有数据 所以就报 找不到数据的错误。 怎么解决呢跪求啊

解决方案 »

  1.   

    可在exception 中 when no_data_found then
                     num1:='';
      

  2.   

    select max(AFG_ISUSED) into num1 from app_config ac where ac.afg_key = '01';
      

  3.   

    捕获  exception 处理 
      

  4.   

    declare
    v_count number;
    num1 number;
    begin
    select count(*) into v_count from app_config ac where ac.afg_key = '01';
    if v_count >0 then
    select AFG_ISUSED into num1 from app_config ac where ac.afg_key = '01';
    else
    num1 := null;
    end if;
    end;
      

  5.   

    6楼正解, 其他的在exception里面处理?  我这行下面的其他语句不用执行了? 
      

  6.   

    6 楼的思路清晰。
    要么写成  
    declare
    num1 number;
    begin
    select AFG_ISUSED into num1 from app_config ac where ac.afg_key = '01';
    exception 
     when no_data_found then 
       num1:=null;
    end;
      

  7.   

    6 楼的思路清晰。
    要么写成  
    declare
    num1 number;
    begin
    select AFG_ISUSED into num1 from app_config ac where ac.afg_key = '01';
    exception 
     when no_data_found then 
       num1:=null;
    end;
      

  8.   

    6楼的做法要select 2次..如果语句复杂的话还是会在一定程度上影响效率的...当然如果单纯的要避免报错的话就直接捕获exception吧..把select语句包含在下面的块中...
    begin
    --select语句
    exception when no_data_found then
    --没值你要干的事情
    end;
    也不会影响到你后面的语句的执行