You are on page 1of 1

Date: Page _____

Experiment - 4
Aim - Introduction and implementation of programs using control structures If-else state-
ments.
Requirement - Oracle

Syntax for IF THEN ELSE Statements: Syntax for NESTED IF ELSE Statements:

IF <condition: returns Boolean> IF <conditionl: returns Boolean>


THEN THEN
-executed only if the condition re- —executed only if the condition re-
turns TRUE turns TRUE
<action_blockl> <action block1 starts>
ELSE IF <condition2: returns Boolean>
-execute if the condition failed (re- THEN
turns FALSE) <action_block2>
<action_block2> END IF; —END IF corresponds to con-
END if; dition2
<action_blockl ends>
Example of IF THEN ELSE: END IF; —END IF corresponds to condition1
END if;
DECLARE
a CHAR(1) :=’u’;
Example of NESTED IF ELSE:
BEGIN
DECLARE
IF a in (‘A’,’E’,’I’,’0’,’U’ ) THEN x NUMBER :=50;
dbms_output.put_line(‘The character is a y NUMBER :=25;
Vowel’); z NUMBER :=10;
BEGIN
ELSEIF a in (‘a’,’e’,’i’,’o’,’u’ ) THEN IF( x > y)THEN
dbms_output.put_line(‘The character is a IF( x > z ) THEN
Vowel’); dbms_output.put_line(‘X is greatest’);
ELSE
ELSE dbms_output.put_line(‘Z is greatest’);
dbms_output.put_line(‘The character is not END IF;
a vowel’); ELSE
END IF; IF( y > z ) THEN
END; dbms_output.put_line(‘Y is greatest’);
/ ELSE
dbms_output.put_line(‘Z is greatest’);
END IF;
END IF;
END;
/

DBMS Lab Milan Kamboj | 18BCS6701 | CSE-25A

You might also like