If-else block in PL/SQL.

If-else: It is a conditional control statement used to create multiple branches in the program . 
its syntax is given as follow:

IF (condition)  then 
..........block.........
ELSE IF (condition ) then
.......block............
ELSE
.........block..........
END IF;


In the above syntax every if statement must be terminated and endif statement for written the condition of it , if there is an arithmetic expression , normally we enclosed the condition inside a bracket.

Example:

Write a PL/SQL  block to read an integer form user and check if it is even or odd and display output.
Syntax:

SET SERVEROUTPUT ON
DECLARE
    i integer ;

BEGIN
    DBMS_OUTPUT.PUT_LINE('ENTER AN INTEGER');
    i:=&i;
    IF (i mod 2=0)then 
        DBMS_OUTPUT.PUT_LINE(i||'is even');
    ELSE
        DBMS_OUTPUT.PUT_LINE(i||'is odd');

END IF;
END;
/

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.