create or replace function sample_oay(partno string,partnote string) return number is
  Result number;
  n  integer;
begin
  --select count(*) into n from dataa146 where part_no like substr(partno,1,8) || '%'
  --   and rownum = 1 and part_no <> partno and oay <> 100;
  --if n > 0 then
  select oay into result from dataa146 where part_no like substr(partno,1,8) || '%'
       and rownum = 1 and part_no <> partno and oay <> 100;
  --end if;
  if result is null then
     if instr(upper(partnote),'SAMPLE') > 0 then
       result := 50;
     else
       result := 70;
     end if;    
  end if;
  return(Result);
end sample_oay;

解决方案 »

  1.   

    表中没记录时,
    select oay into result from dataa146 where part_no like substr(partno,1,8) || '%'
           and rownum = 1 and part_no <> partno and oay <> 100;
    执行错误的,必须加表中有无记录的判断
      

  2.   

    這樣的話寫代碼也太繁了,在SQL Server中是無此限制的,請問有無其他實現方法,寫
    這樣的代碼覺得很沒勁,呵呵。請問lndy在寫類似代碼時都這樣寫嗎,TKS
      

  3.   

    Exception
        when no_data_found then
              你要做的事情;
      

  4.   

    Very Good,再過一小時結貼,還有別的見解嗎?
      

  5.   

    create or replace function sample_oay(partno string,partnote string) return number is
    Result number;
    n integer;
    cursor c_test is
    select oay from dataa146 where part_no like substr(partno,1,8) || '%'
    and rownum = 1 and part_no <> partno and oay <> 100;beginopen c_test;
    fetch c_test into result;
    if result is null then
    if instr(upper(partnote),'SAMPLE') > 0 then
    result := 50;
    else
    result := 70;
    end if;
    end if;
    close c_test;
    return(Result);
    end sample_oay;