PL/SQL - Conditional Statements

Conditional Statements

The following code segment shows the IF-THEN-ELSIF construct. The ELSIF and ELSE parts are optional so it is possible to create simpler IF-THEN or, IF-THEN-ELSE constructs.

IF x = 1 THEN sequence_of_statements_1; ELSIF x = 2 THEN sequence_of_statements_2; ELSIF x = 3 THEN sequence_of_statements_3; ELSIF x = 4 THEN sequence_of_statements_4; ELSIF x = 5 THEN sequence_of_statements_5; ELSE sequence_of_statements_N; END IF;

The CASE statement simplifies some large IF-THEN-ELSE structures.

CASE WHEN x = 1 THEN sequence_of_statements_1; WHEN x = 2 THEN sequence_of_statements_2; WHEN x = 3 THEN sequence_of_statements_3; WHEN x = 4 THEN sequence_of_statements_4; WHEN x = 5 THEN sequence_of_statements_5; ELSE sequence_of_statements_N; END CASE;

CASE statement can be used with predefined selector:

CASE x WHEN 1 THEN sequence_of_statements_1; WHEN 2 THEN sequence_of_statements_2; WHEN 3 THEN sequence_of_statements_3; WHEN 4 THEN sequence_of_statements_4; WHEN 5 THEN sequence_of_statements_5; ELSE sequence_of_statements_N; END CASE;

Read more about this topic:  PL/SQL

Famous quotes containing the words conditional and/or statements:

    Conditional love is love that is turned off and on....Some parents only show their love after a child has done something that pleases them. “I love you, honey, for cleaning your room!” Children who think they need to earn love become people pleasers, or perfectionists. Those who are raised on conditional love never really feel loved.
    Louise Hart (20th century)

    We assume that politicians are without honor. We read their statements trying to crack the code. The scandals of their politics: not so much that men in high places lie, only that they do so with such indifference, so endlessly, still expecting to be believed. We are accustomed to the contempt inherent in the political lie.
    Adrienne Rich (b. 1929)