📜  PL / SQL-条件

📅  最后修改于: 2020-11-26 05:52:14             🧑  作者: Mango


在本章中,我们将讨论PL / SQL中的条件。决策结构要求程序员指定一个或多个要由程序评估或测试的条件,如果确定条件为真,则指定要执行的一个或多个语句,如果条件为真,则可选地指定要执行的其他语句。条件确定为假。

以下是大多数编程语言中常见的典型条件(即决策)结构的一般形式-

PL / SQL中的决策声明

PL / SQL编程语言提供以下类型的决策语句。单击以下链接以查看其详细信息。

S.No Statement & Description
1 IF – THEN statement

The IF statement associates a condition with a sequence of statements enclosed by the keywords THEN and END IF. If the condition is true, the statements get executed and if the condition is false or NULL then the IF statement does nothing.

2 IF-THEN-ELSE statement

IF statement adds the keyword ELSE followed by an alternative sequence of statement. If the condition is false or NULL, then only the alternative sequence of statements get executed. It ensures that either of the sequence of statements is executed.

3 IF-THEN-ELSIF statement

It allows you to choose between several alternatives.

4 Case statement

Like the IF statement, the CASE statement selects one sequence of statements to execute.

However, to select the sequence, the CASE statement uses a selector rather than multiple Boolean expressions. A selector is an expression whose value is used to select one of several alternatives.

5 Searched CASE statement

The searched CASE statement has no selector, and it’s WHEN clauses contain search conditions that yield Boolean values.

6 nested IF-THEN-ELSE

You can use one IF-THEN or IF-THEN-ELSIF statement inside another IF-THEN or IF-THEN-ELSIF statement(s).