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:

Get more Vinish.dev tutorials on Google

See my articles more often when you search Google.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted