Thursday, 24 May 2012

What are the different forms of conditional IF construct? | PL SQL

 There are three forms of IF construct, which are given as follows:
i. IF-THEN — Associates a condition with sequence of statements. Following is the syntax of the IF-THEN construct:
 IF condition THEN
Statements for Processing ....
END IF;

ii. IF-THEN-ELSE — Associates one set of statements (within the IF block), which are executed when the condition given with the IF clause is TRUE, and second set of statements (within the ELSE block), which are executed when the condition is FALSE. Following is the syntax of the IF-THEN-ELSE construct:
 IF condition THEN
Statements for Processing ....
ELSE
Statement for Processing ....
END IF;

iii. IF-THEN-ELSIF — Allows different set of statements to be executed under multiple conditions. When none of the condition is TRUE, then the ELSE block of the condition is executed. Following is the syntax of the IF-THEN-ELSEIF construct:
 IF condition THEN
Statements1 for Processing ....
ELSEIF condition THEN
Statements2 for Processing ....
ELSEIF condition THEN
Statements3 for Processing ....
ELSE
Statements4 for Processing ....
END IF;