Oracle IF Condition Example

In Oracle PL/SQL, IF condition is used to perform a logical check on certain values. If the condition is TRUE or FALSE then executes the statements followed by that condition. In this blog post, I am giving an Oracle IF Condition example with it's syntax information.

Syntax

IF boolean_condition THEN
  -- statements to execute
ELSIF boolean_condition THEN
  -- statements to execute
ELSE
  -- statements to execute
END IF;

Oracle IF Condition Example

In the following example, the PL/SQL program will check the variable a value using IF Condition, that if it is NULL or is between 1 to 9 or is greater than 9 and then whichever the condition is true, will print on the screen.

SET SERVEROUTPUT ON;
DECLARE
a NUMBER;
BEGIN
a := 10;
IF a IS NULL
THEN
DBMS_OUTPUT.put_line ('a is null.');
ELSIF a > 0 AND a < 10
THEN
DBMS_OUTPUT.put_line ('a is between 1 to 9.');
ELSE
DBMS_OUTPUT.put_line ('a is greater than 9.');
END IF;
END;
/

Output:

a is greater than 9.
PL/SQL procedure successfully completed.

See also:

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.