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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:36:05  来源:igfitidea点击:

ELSIF V/S ELSE IF IN ORACLE

oracleoracle11g

提问by Nisar

what is difference between those two.

这两者有什么区别。

elsif

else if

while both are executing fine with no errors.

虽然两者都运行良好,没有错误。

回答by Justin Cave

An IFstatement in PL/SQL is structured as

IFPL/SQL 中的语句结构如下

IF <<some condition>>
THEN
  <<do something>>
ELSIF <<another condition>>
THEN
  <<do something else>>
ELSE
  <<do a third thing>>
END IF;

where both the ELSIFand the ELSEare optional. If you are seeing an ELSE IF, that indicates that someone is creating a nested IFstatement (with a nested END IF) in an ELSEblock. That is

其中 theELSIF和 theELSE都是可选的。如果您看到ELSE IF,则表示有人正在块中创建嵌套IF语句(带有嵌套的END IFELSE。那是

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 IFstatement, you're much more likely to produce readable code using a single IFstatement with one or more ELSIFblocks (or, even better, a CASE). Plus, that way you're not trying to count up all the END IFstatements you need to close all the nested IFstatements.

如果您愿意,您可以将 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

Oracle 上的 PL/SQL 控制语句?数据库 PL/SQL 语言参考