Oracle 为什么我的异常会阻止代码运行

Oracle 为什么我的异常会阻止代码运行,oracle,plsql,oraclereports,Oracle,Plsql,Oraclereports,我是一名实习开发人员,负责其他人的代码,因此我的大部分工作将是修改他们的工作。我正在Oracle 10g上使用报表生成器 我在公式中有以下设置: function get_addressFormula return Char is begin if :payee_ctc_id is not null then begin select a.address ,a.address2 ,a.address3 ,g.location

我是一名实习开发人员,负责其他人的代码,因此我的大部分工作将是修改他们的工作。我正在Oracle 10g上使用报表生成器

我在公式中有以下设置:

function get_addressFormula return Char is
begin
if :payee_ctc_id is not null then
begin
 select  a.address
        ,a.address2
        ,a.address3
        ,g.location
            ,g.ppostcode
 into    :address1
        ,:address2
        ,:address3
        ,:address4
        ,:postcode

 from ctc_address a
     ,geo_locations g

 where a.addresstypeid = 1  
 and   a.costcentreid = :payee_ctc_id
 and   g.locationid = a.locationid
 and   a.addressid = (select max(i.addressid)   
                      from  ctc_address i
            where i.costcentreid = :payee_ctc_id
            and   i.addresstypeid = 1);

exception
    when others then
      return null;

    while trim(:address1) is null and (trim(:address2) is not null or trim(:address2)  is not null or trim(:address4) is not null)
    loop
      :address1 := :address2; 
      :address2 := :address3; 
      :address3 := :address4; 
      :address4 := '';
    end loop;

    while trim(:address2) is null and (trim(:address3) is not null or trim(:address4) is not null)
    loop
      :address2 := :address3; 
      :address3 := :address4; 
      :address4 := '';
    end loop;

    while trim(:address3) is null and trim(:address4) is not null
    loop
      :address3 := :address4; 
      :address4 := '';
    end loop;

end;
else
 begin
  <else code>
 end;
 end if;

return 'y';
end;
这是除最后一个else块之外的全部函数。我尝试了没有找到任何数据,但仍然不起作用

@tbone。我不知道该怎么做。到目前为止,我在谷歌上搜索了一下加薪信息,但运气不佳。

参见:

还要注意的是,当其他人没有加薪时,使用WHEN是一个坏习惯。你不想忽略所有的错误,所以要明确。通常您只想捕获未找到的数据。

请参阅:


还要注意的是,当其他人没有加薪时,使用WHEN是一个坏习惯。你不想忽略所有的错误,所以要明确。通常,您只希望捕获未找到的数据。

您可能希望实际引发异常,而不是捕获异常并返回null,这就是您不知道到底发生了什么的原因。能否向我们展示更多代码并指出未执行的代码?如果异常后的代码从未执行,这意味着总是抛出异常,并且块以RETURN nulls结尾。很难对此进行评论,因为一些重要的语法已从示例中删除。您可能希望实际引发异常,而不是捕获异常并返回null,这就是为什么您不知道到底发生了什么。您能向我们展示更多代码并指出吗未执行的代码?如果异常后的代码从未执行,这意味着总是抛出异常,并且块以RETURN nulls结束。很难对此进行评论,因为一些重要的语法已从示例中删除。谢谢。你能告诉我怎么用RAISE吗?如前所述,没有找到数据也不起作用。我在《蟾蜍》中写了一个修改版本,并尝试了不同的东西。还没有运气。我将在我们的其他过程中对RAISE示例进行讨论。@arend在您的示例中,在返回NULL后添加代码是没有意义的:此代码永远不会运行。块由BEGIN/END定义,因此您的END应该在返回NULL之后,而不是在ELSE之前。您可以使用引发异常。但在大多数情况下,如果您没有记录错误,最好不要在其他人出现错误时使用。让未知错误传播,捕捉意外异常是没有意义的。我做了我应该先尝试的。我将异常块移到end语句的正上方。我用有效值和无效值对它进行了测试,结果很好。谢谢谢谢你,文森特。你能告诉我怎么用RAISE吗?如前所述,没有找到数据也不起作用。我在《蟾蜍》中写了一个修改版本,并尝试了不同的东西。还没有运气。我将在我们的其他过程中对RAISE示例进行讨论。@arend在您的示例中,在返回NULL后添加代码是没有意义的:此代码永远不会运行。块由BEGIN/END定义,因此您的END应该在返回NULL之后,而不是在ELSE之前。您可以使用引发异常。但在大多数情况下,如果您没有记录错误,最好不要在其他人出现错误时使用。让未知错误传播,捕捉意外异常是没有意义的。我做了我应该先尝试的。我将异常块移到end语句的正上方。我用有效值和无效值对它进行了测试,结果很好。谢谢
<< label >> (optional)
DECLARE    -- Declarative part (optional)
  -- Declarations of local types, variables, & subprograms

BEGIN      -- Executable part (required)
  -- Statements (which can use items declared in declarative part)

[EXCEPTION -- Exception-handling part (optional)
  -- Exception handlers for exceptions (errors) raised in executable part]
END;
if :payee_id is not null then    
   begin
      <Select statement which place results into placeholders>
   exception
      when NO_DATA_FOUND then
         return null;
   end;
   <code>    
else
   <else code>
end if;