我想按如下方式编写程序:
begin
if(condn1) then
statements;
end if ;
exception part
end ;
begin
if(condn2) then
statements;
end if ;
exception part
end ;
当我尝试编译此包时,我收到以下错误:
LINE/COL ERROR
-------- -----------------------------------------------------------------
509/5 PLS-00103: Encountered the symbol "WHEN" when expecting one of
the following:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
The symbol "case" was substituted for "WHEN" to continue.
545/10 PLS-00103: Encountered the symbol ";" when expecting one of the
following:
case
答案 0 :(得分:4)
如果要包含多个异常部分,则必须为所需的每个异常部分包含整个块。块结构是:
DECLARE [Optional]
... [Optional]
BEGIN
...
EXCEPTION
WHEN ... THEN
...
END;
因此,具有2个异常部分的代码应类似于以下代码:
DECLARE
your_variables;
BEGIN
BEGIN
IF condition_1 THEN
statements;
END IF;
EXCEPTION
WHEN your_exceptions_for_part_1 THEN
...
END;
BEGIN
IF condition_2 THEN
statements;
END IF;
EXCEPTION
WHEN your_exceptions_for_part_2 THEN
...
END;
EXCEPTION
WHEN common_exceptions THEN
...
END;