ELSIF V/S ELSE IF 在 ORACLE 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22971437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ELSIF V/S ELSE IF IN ORACLE
提问by Nisar
what is difference between those two.
这两者有什么区别。
elsif
else if
while both are executing fine with no errors.
虽然两者都运行良好,没有错误。
回答by Justin Cave
An IF
statement in PL/SQL is structured as
IF
PL/SQL 中的语句结构如下
IF <<some condition>>
THEN
<<do something>>
ELSIF <<another condition>>
THEN
<<do something else>>
ELSE
<<do a third thing>>
END IF;
where both the ELSIF
and the ELSE
are optional. If you are seeing an ELSE IF
, that indicates that someone is creating a nested IF
statement (with a nested END IF
) in an ELSE
block. That is
其中 theELSIF
和 theELSE
都是可选的。如果您看到ELSE IF
,则表示有人正在块中创建嵌套IF
语句(带有嵌套的END IF
)ELSE
。那是
IF <<some condition>>
THEN
<<do something>>
ELSE
IF <<another condition>>
THEN
<<do something else>>
END IF;
END IF;
You can, if you so desire, nest PL/SQL blocks as deeply as you'd like. Generally, though, your code will be cleaner if you don't nest things more than necessary. Unless there is a compelling reason here to create a nested IF
statement, you're much more likely to produce readable code using a single IF
statement with one or more ELSIF
blocks (or, even better, a CASE
). Plus, that way you're not trying to count up all the END IF
statements you need to close all the nested IF
statements.
如果您愿意,您可以将 PL/SQL 块嵌套到您希望的深度。但是,通常情况下,如果您不嵌套不必要的东西,您的代码会更干净。除非这里有令人信服的理由来创建嵌套IF
语句,否则您更有可能使用IF
包含一个或多个ELSIF
块(或者更好的是 a CASE
)的单个语句生成可读代码。另外,这样您就不会试图计算END IF
关闭所有嵌套IF
语句所需的所有语句。
回答by Joseph B
ELSIF does not need a matching END IF. If the condition for the 1st IF is not satisfied, then the ELSIF condition is checked.
ELSIF 不需要匹配的 END IF。如果不满足第一个 IF 的条件,则检查 ELSIF 条件。
ELSE IF will need a matching END IF, because a new IF block is started.
ELSE IF 将需要匹配的 END IF,因为新的 IF 块已启动。
References:
参考资料:
PL/SQL Control Statements on Oracle? Database PL/SQL Language Reference