Skip to content

ELSEIF

DECLARE
num1 NUMBER := 100;
num2 NUMBER := 20;
BEGIN
IF num1 > num2 THEN
DBMS_OUTPUT.PUT_LINE('Num1 is greater than Num2');
ELSEIF num1 < num2 THEN
DBMS_OUTPUT.PUT_LINE('Num1 is less than Num2');
ELSE
DBMS_OUTPUT.PUT_LINE('Num1 is equal to Num2');
END IF;
END;
/
Num1 is greater than Num2

In the given example, the number values are compared using the IF-ELSEIF-ELSE construct. First, the code checks if num1 is greater than num2. If the condition is true, it outputs ‘Num1 is greater than Num2’. If the condition is false, the ELSEIF statement checks if num1 is less than num2. If it’s false again, then the ELSE statement executes, and it outputs ‘Num1 is equal to Num2’. In this case, because num1 is greater than num2, the output is ‘Num1 is greater than Num2’.