Updated on 2023-10-31 GMT+08:00

Conditional Statements

Conditional statements are used to decide whether given conditions are met. Operations are executed based on the decisions made.

GaussDB(DWS) supports five usages of IF:

  • IF_THEN
    Figure 1 IF_THEN::=

    IF_THEN is the simplest form of IF. If the condition is true, statements are executed. If it is false, they are skipped.

    Example

  • IF_THEN_ELSE
    Figure 2 IF_THEN_ELSE::=

    IF-THEN-ELSE statements add ELSE branches and can be executed if the condition is false.

    Example

  • IF_THEN_ELSE IF

    IF statements can be nested in the following way:

    Actually, this is a way of an IF statement nesting in the ELSE part of another IF statement. Therefore, an END IF statement is required for each nesting IF statement and another END IF statement to end the parent IF-ELSE statement. To set multiple options, use the following form:

  • IF_THEN_ELSIF_ELSE
    Figure 3 IF_THEN_ELSIF_ELSE::=

    Example

  • IF_THEN_ELSEIF_ELSE

    ELSEIF is an alias of ELSIF.

    Example