Plsql 简明教程

PL/SQL - Conditions

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

In this chapter, we will discuss conditions in PL/SQL. Decision-making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

以下是大多数编程语言中常见的条件(即决策制定)结构的通用形式 −

Following is the general form of a typical conditional (i.e., decision making) structure found in most of the programming languages −

decision making

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

PL/SQL programming language provides following types of decision-making statements. Click the following links to check their detail.

S.No

Statement & Description

1

IF - THEN statementThe 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 statementIF 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 statementIt allows you to choose between several alternatives.

4

Case statementLike 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 statementThe searched CASE statement has no selector, and it’s WHEN clauses contain search conditions that yield Boolean values.

6

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