Syntax for IF THEN ELSE statement in Oracle PL/SQL

Example for IF THEN ELSE statement in Oracle PL/SQL

IF THEN ELSE is used to based on condition, If condition is true then run the statement present in blocks else run statement in else block.

Syntax:

IF <condition> THEN
   <statements>
ELSE   
   <statements>
END IF;

-- You also use ELEIF condition inbetween 

IF <condition> THEN
   <statements>
ELSIF <condition> THEN
   <statements>
ELSE 
   <statements>
END IF;

Example of IF THEN ELSE Statements:

SET SERVEROUTPUT ON
DECLARE 
   v_id number(2); 
BEGIN 
   v_id := 1;
   IF v_id < 5
        dbms_output.put_line('Number is less than 5'); 
    ELSE 
	dbms_output.put_line('Number is greater or equal to 5'); 
   END IF; 
END; 
/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.